0 votes
by (240 points)

Hi,
I need to download and delete all CSV files which have a name starting with "cash" or "EFT" or "DDR".

I have implemented download and delete for csv but not sure on how to check for the filename.

Please suggest.

Thanks,
Vinay

Applies to: Rebex SFTP

1 Answer

+1 vote
by (72.7k points)
selected by
 
Best answer

This can be easily done using the Rebex.IO.FileSet class:

// define FileSet
var set = new FileSet("/home/data");
set.Include("cash*.csv");
set.Include("EFT*.csv");
set.Include("DDR*.csv");

Then you can use it like this:

// download then delete
client.Download(set, @"C:\data");
client.Delete(set);

Or even in single line:

// move = after succesfull download delete file immediately
client.Download(set, @"C:\data",  TransferMethod.Move, ActionOnExistingFiles.ThrowException);
by (240 points)
Thanks, Lukas.
Another question I have is below single line download delete the file only if the download is successful?
client.Download(set, @"C:\data",  TransferMethod.Move, ActionOnExistingFiles.ThrowException);
by (72.7k points)
Yes. The proces goes like this:

for each file
  Download file
  Delete file

If Download file fails or file is skipped, the Delete file is not performed.
...