Why are some scripting commands specified on WinSCP command-line in a batch file not executed/failing?

New-line Escaping

Many examples on this site, as well as batch file template generated by WinSCP, use new-line escaping using caret sign ^ to allow wrapping a long command line to multiple lines for a better readability:

winscp.com /command ^
    "open sftp://username:password@example.com/" ^
    "get *" ^
    "exit"

When reusing/modifying such script, users frequently find that WinSCP seemingly stops processing the commands in a middle or behaves strangely.

This is commonly caused by improper syntax of the new-line escaping in the batch file (and as such is not WinSCP issue at all). For the new-line escaping to work as expected, the caret sign ^ has to be the very last character on the line (no spaces after it) and the next line needs to be indented (at least one space at the front).

Double Double-quotes

When using /command switch, each script command needs to be surrounded by double quotes. As parameters of commands themselves may need to be surrounded by double quotes, those need to be doubled.

For details, see escaping the in-command double-quotes by doubling them.

Last modified: by martin