문제

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
도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top