Your batch file is interpreted by Windows command interpreter, the cmd.exe
, line-by-line.
So once winscp.com
line is reached, the interpreter runs winscp.com
and waits for it to exit (what it never does on its own). If it had exited, the interpreter would keep executing the other commands failing the most (as they are not valid Windows commands).
The lines that are actually WinSCP commands, not Windows commands, have to be fed to WinSCP, not to the cmd.exe
.
See also WinSCP FAQ Why are some WinSCP scripting commands specified in a batch file not executed/failing?
Before continuing, let me fix your wrong WinSCP syntax. For automation, you do not use the session URL on WinSCP command line, you use open
command instead. My following examples will use that instead.
There are two ways:
Separate the WinSCP commands into a separate WinSCP script file, say script.txt
:
open sftp://userid:password@hostname
cd /var/tmp
call ./script.sh
get /var/tmp/log.txt C:\Preeti\log.txt
exit
And run it like:
cd C:\Program Files\WinSCP
winscp.com /script=c:\path\to\script.txt
Using WinSCP /command
command-line switch, you can keep everything in a single file (the batch file) with a syntax like:
cd C:\Program Files\WinSCP
winscp.com /command ^
"open sftp://userid:password@hostname" ^
"cd /var/tmp" ^
"call ./script.sh" ^
"get /var/tmp/log.txt C:\Preeti\log.txt" ^
"exit"
You should read WinSCP guide to automating file transfers to SFTP server.