Using Winscp.com in a Batchfile with Escape characters

Moriarty91
Joined:
Posts:
1

Using Winscp.com in a Batchfile with Escape characters

Hello!
I am writing a batchfile to automatically upload a file to an sftp-server.
Using the following code works fine:
 C:\patch\to\winscp.com /log="C:\path\winscp.log" /loglevel=1 /command ^
"open user@sftp.psubdomain.server.com -privatekey=C:\path\key.ppk -hostkey=XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX" "put -resume -resumesupport=on -transfer=binary -delete C:\path\%filename%.ext users/name/path/" "exit"

But using the following code which I have copied from the documentation produces errors:
C:\patch\to\winscp.com /log="C:\path\winscp.log" /loglevel=1 ^
"open user@sftp.psubdomain.server.com -privatekey=C:\path\key.ppk -hostkey=XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX" ^
"put -resume -resumesupport=on -transfer=binary -delete C:\path\%filename%.ext users/name/path/" ^
"exit"
I have copied the codesample above from the documentation and WinSCP either says "Unknown command: ^" after executing the "open ..." line (so the second ^ is not recognized) and the following WinSCP-commands "put..." and "exit" are then interpreted by cmd in the batch file and not WinSCP as part of its commands.
The other error I get from WinSCP is "Unknown command: open user@sftp.psubdomain.server.com -privatekey=C".
I have not figured out, which error is triggered when and I don't know what is wrong as the logfile simply seems to repeat these errors.
Thanks for your help!
Moriarty91

martin
Site Admin
Joined:
Posts:
31,060
Location:
Prague, Czechia

Re: Using Winscp.com in a Batchfile with Escape characters

The ^ in Windows batch file delimiter (it has nothing to do with WinSCP).
Make sure it's the very last character on the line (there cannot be any space after it).
And you typically need a space at the front of the next line.

See https://winscp.net/eng/docs/faq_batch_file

You can post new topics in this forum