How to get and delete files from multiple directories and subdirectories

Advertisement

rlf
Joined:
Posts:
1

How to get and delete files from multiple directories and subdirectories

Hi there,

I've got the folllowing directory structure on a FTP server:
/data/
/data/200100/T2251/
/data/200100/T2252/
/data/200200/T3051/
/data/200300/T6051/

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\
exit 
But it didn't work. Can someone help me how to do it correctly?

Thanks in advance
ralf

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,518
Location:
Prague, Czechia

Re: How to get and delete files from multiple directories and subdirectories

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.

See https://winscp.net/eng/docs/guide_interpreting_xml_log

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.

References:
https://winscp.net/eng/docs/library_session_getfiles
https://winscp.net/eng/docs/library_transferoperationresult
https://winscp.net/eng/docs/library_session_removefiles

Reply with quote

Advertisement

You can post new topics in this forum