WinSCP time based file download

后端 未结 1 761
谎友^
谎友^ 2020-12-04 00:57

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?

相关标签:
1条回答
  • 2020-12-04 01:32

    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.

    0 讨论(0)
提交回复
热议问题