Topic "How to get and delete files from multiple directories and subdirectories"

Author Message
[View user's profile]

Joined: 2015-11-28
Posts: 1
Hi there,

I've got the folllowing directory structure on a FTP server:

In every directory should be pdf files and I didn't know the subdirectory names. Only /data is what I know. I want to get all pdf files and delete them after downloading.

I tried different scripts at least the following script
open sftp://xxx:yyy@server:22
get -delete /data/*.PDF D:\pdf_data\
get -delete /data/2*/*.PDF D:\pdf_data\
get -delete /data/2*/T*/*.PDF D:\pdf_data\

But it didn't work. Can someone help me how to do it correctly?

Thanks in advance
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26890
Location: Prague, Czechia
There's no easy solution for this using WinSCP scripting.

All you can do is using plain get with enabled XML logging. After the download finishes, parse the XML log to find a list of downloaded files and generate delete script for these.


Though easier is to use PowerShell script with WinSCP .NET assembly.

- Do a regular download = do not set remove parameter of Session.GetFiles to true.
- Iterate TransferOperationResult.Transfers returned by the Session.GetFiles.
- For each successful download of a file, call Session.RemoveFiles.


You can post new topics in this forum


What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!


About donations

$9   $19   $49   $99

About donations


WinSCP Privacy Policy

WinSCP License