0 votes
by (190 points)

My question is if I can be sure that when using the

Task DownloadAsync(string remotePath, string localDirectoryPath, TraversalMode traversalMode, TransferMethod transferMethod, ActionOnExistingFiles existingFileMode, object state = null)

function with TransferMethod = Move, items are only deleted in the source server if they were successfully downloaded to the targeted local folder.

If an internal exception happens in Regex.Sftp (for example "Rebex.Net.SftpException: Error when retrieving items from a remote directory ('DirName'). Failure."), can I be sure that the source file was NOT deleted?

Version: Rebex SFTP (2018 R4) for .NET 4.0-4.7

Thank you!

Applies to: Rebex SFTP

1 Answer

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

Each item is deleted after it has been successfully transferred.
If you are transferring 10 files, this is what's going on:

  1. Download file1
  2. Delete file1.
  3. Download file2
  4. Delete file2
  5. Download file3
  6. Delete file4
    ... and so on...

So, for example, if this fails at step 5, then file1/file2 would be deleted at the server, while file3/file4/... would remain there.

If you instead prefer to only delete all the files at once after all of them have been successfully transferred, consider using GetItems method to retrieve a list of files to be downloaded. Then iterate over the list, downloading each file using GetFile method. After all of the files have been downloaded, iterate over the list again, calling DeleteFile or RemoveDirectory.