I'm trying to download files from a big tree of recursive directories, and I want the downloaded files to be removed after download. When I put true
in remove
parameter of GetFiles
, it removes all the directories, but I want it to remove only the files and leave the directories empty. Is there any way to do it? Thank you.
Asked
Active
Viewed 3,941 times
4

Martin Prikryl
- 188,800
- 56
- 490
- 992

user5441417
- 101
- 3
- 9
1 Answers
3
Use WinSCP extension Recursively move files in directory tree to/from SFTP/FTP server while preserving source directory structure.
Some alternatives:
- Do a regular download = do not set
remove
parameter ofSession.GetFiles
to true. - Iterate
TransferOperationResult.Transfers
returned by theSession.GetFiles
. - For each successful download of a file, call
Session.RemoveFiles
.
A more complicated, but more efficient (if you have a large amount of files) approach would be:
- Replicate the directory structure in a remote temporary folder.
- Move all the files there, directory by directory, using
Session.MoveFile
. Despite the name, the method accepts wildcards. - Download and delete the temporary tree at once using
Session.GetFiles
withremove
set totrue
.

Martin Prikryl
- 188,800
- 56
- 490
- 992