0 votes
by (240 points)

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.


Applies to: Rebex SFTP

1 Answer

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

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

// define FileSet
var set = new FileSet("/home/data");

Then you can use it like this:

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

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 (70.4k 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.