Search code examples
batch-filewinscp

WinSCP timestamp as a user input/from file


I have a WinSCP command in a batch file as described below:

get -neweronly event_%TIMESTAMP#yyyymmdd%_0000.db C:\events\test

What I want to do is set the TIMESTAMP from a user input (e.g. from a text file) I do not want to use the current computer time - Is this possible?

If I put a date of 20180101 in a text file and import it, would this be the solution?

set /p TIMESTAMP=<Timestampdate.txt

Would I need to do anything to the TIMESTAMP in the get -neweronly event_%TIMESTAMP#yyyymmdd%_0000.db C:\events\test?


Solution

  • If you want to use an environment variable in WinSCP script, use syntax %NAME%. The #yyyymmdd part cannot be there, nor does it make any sense.

    And while WinSCP will not override an existing TIMESTAMP variable with its own value, it's definitely better to use a different name, to avoid ambiguity. After all, your variable is just a generic environment variable, it has nothing to with WinSCP TIMESTAMP syntax.

    In batch file:

    set /p MYTIMESTAMP=<Timestampdate.txt  
    

    In WinSCP script:

    get -neweronly event_%MYTIMESTAMP%_0000.db C:\events\test