Variable in WinSCP script

5,559

There's indeed no set command in WinSCP.

The set command, with syntax you are using, is a Windows command.

As such, you need to execute it from a Windows batch file, such as yours ftprun.cmd.

WinSCP can resolve Windows environment variables in its script:

So all you actually need to do is to move the set line to the ftprun.cmd, before the call to winscp.com:

set mydate=%date:~6,4%%date:~3,2%%date:~0,2%
"C:\Program Files\WinSCP\winscp.com" /script=D:\testsftp\ftpscript.txt

Anyway, note that your date magic is locale-specific, so make sure that every machine, where you use the script, use the same locale (language) as the machine you develop/test this on. For example with my Czech locale, the mydate resolves to nonsense 06.12čt, because the date is čt 12. 06. 2014.

Better solution, is to use the WinSCP %TIMESTAMP% syntax:

mkdir %TIMESTAMP#yyyymmdd%
Share:
5,559

Related videos on Youtube

Bean Tee
Author by

Bean Tee

Updated on September 18, 2022

Comments

  • Bean Tee
    Bean Tee over 1 year

    I'm asked to automate some SFTP download processes via WinSCP. I'm not familiar with WinSCP scripting.

    ftprun.cmd:

    C:\Program Files\WinSCP\winscp.com" /script=D:\testsftp\ftpscript.txt
    

    ftpscript.txt:

    option batch continue
    option confirm off
    open [email protected]
    set mydate=%date:~6,4%%date:~3,2%%date:~0,2%
    cd /cygdrive/h/ftproot/PROD/MRMRSA/eMotor/
    lcd D:\testsftp
    mkdir %mydate%
    exit
    

    When I run the script, system shows

    Unknown command 'set'.

    Have been searching high and low to solve this but no luck.