1

I am trying to create a script that transfers a file from a local windows folder to a unix environment through SFTP. I made a slight change (concatenated FX%timestamp%.txt) to the code so that the filename to be sent is equal to the date today.

The code already works when I copy these commands to the command prompt. Result: Files get copied from c:\upload to opt/dev/public_html/TEST/aperture/public/fx_rates

"C:\Program Files\WinSCP\WinSCP.com" ^
  /command ^
    "open sftp://ApertureUATusr:[email protected]/ -hostkey=""ssh-ed25519 256 f1:bd:8f:ad:ae:6f:93:a9:e5:ae:79:64:03:49:0a:09""" ^
    "lcd C:\upload" ^
    "cd /opt/dev/public_html/TEST/aperture/public/fx_rates" ^
    "put -transfer=ascii -permissions=0777 FX%TIMESTAMP#yyyymmdd%.txt" ^
    "exit"

The problem is that this code doesn't run as a .BAT file. I managed to get a screenshot when I run the batfile and as I checked the error, the system reads it as FX.txt instead of FX20180221.txt enter image description here

1 Answer 1

2

As mentioned in documentation for the WinSCP %TIMESTAMP% syntax:

To use %TIMESTAMP...% on a command-line in a batch file, you need to escape the % by doubling it to %%TIMESTAMP...%%, to avoid a batch file interpreter trying to resolve the variable.

So you need this:

    "put -transfer=ascii -permissions=0777 FX%%TIMESTAMP#yyyymmdd%%.txt" ^
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.