Question

I would like to write WinSCP script to download a file that is placed onto the remote server every morning between 4-4:30am. Is there a way to do this with time-stamping?

I want to pseudocode:

get file.txt where timestap<1 hour from 4 am
Was it helpful?

Solution

First, I assume your file does not have fixed name (contrary to your question with fixed name file.txt). If not, please explain, why do you need timestamp-based solution.


Anyway, you can use a file mask with a time constraint:

get "*.txt>2014-07-19 4:00"

To dynamically inject today's date, use the %TIMESTAMP% syntax:

get "*.txt>%TIMESTAMP#yyyy-mm-ss% 4:00"

Simply, the above means, get all files created later than 4:00 today (the %TIMESTAMP#yyyy-mm-ss% resolves to today's date in format yyyy-mm-ss, as needed for the time constraint).

When passing the get on WinSCP command-line in a batch file (using /command switch, as opposite to using /script switch to specify a separate script file), you have to double the % to avoid the batch-file trying to interpret the %TIMESTAMP%:

winscp.com /command ... "get ""*.txt>%%TIMESTAMP#yyyy-mm-ss%% 4:00"""

Another solution is a static script that rely on a relative time: E.g. you know your script runs at 6am. So you let WinSCP download all files updated/created in the last 2 hours (6am – 4am):

get *.txt>2h

See also WinSCP article on downloading the most recent file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top