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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…