Download last two weeks of files from a FTP folder

Advertisement

gilbreen
Joined:
Posts:
2

Download last two weeks of files from a FTP folder

There are two files generated every day by one of our partner agencies, one in the morning and one in the evening and they are placed on their FTP site. The file's naming structure starts with the current date and then adds a randomly generated number.

Their FTP site holds all generated files going back to June 2022. We currently use a script with WinSCP to synchronize their FTP site to a local folder which means our local folder contains all files going back to June 2022.

Our agency only needs the last two weeks of files at any give time. Instead of keeping all the files back to June 2022 in our local folder, is there a way to have WinSCP only download/synchronize the files for the last two weeks?

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
40,702
Location:
Prague, Czechia

Re: Download last two weeks of files from a FTP folder

It's easy if you can rely on file timestamps:
get /remote/path/*>14D
See https://winscp.net/eng/docs/file_mask#size_time

If you have to rely on the date in the filename, it is more difficult. You can use 14 get commands, one for each day (or one command with 14 masks):
cd /remote/path
get %TIMESTAMP#yyyy-mm-dd%*
get %TIMESTAMP-1D#yyyy-mm-dd%*
get %TIMESTAMP-2D#yyyy-mm-dd%*
...
get %TIMESTAMP-13D#yyyy-mm-dd%*
(assumes that filename has format yyyy-mm-dd*)
See https://winscp.net/eng/docs/scripting#timestamp

Reply with quote

Advertisement

You can post new topics in this forum