This is an old revision of the document!
Scripting/Automation
See Command-line parameters to learn how to enter the console/scripting mode.
Advertisement
Commands
Following commands are implemented: cd
, chmod
, close
, exit
, get
, help
, keepuptodate
, lcd
, lls
, ln
, lpwd
, ls
, mkdir
, mv
, open
, option
, put
, pwd
, rm
, rmdir
, session
, synchronize
and several aliases.
Command help <command>
shows comprehensive description of the command
including examples and aliases.
Multiple sessions can be opened simultaneously. Use session
command to switch among them. Commands can be read from script file.
By default interactive mode is used (user is prompted in the same way as in GUI mode). To switch to batch mode (all prompts are automatically answered negatively) use command option batch on
. For the batch mode it is recommended to turn off confirmations using option confirm off
to allow overwrites (otherwise the overwrite confirmation prompt would be answered negatively, making overwrites impossible).
WinSCP returns exit code 1, when any command is interrupted due to an error or any prompt is answered Abort (even automatically in batch mode). Otherwise it returns exit code 0.
Console Interface Tool
As WinSCP3.exe
is GUI application, it cannot inherit console window when run from other console application (like Windows command-prompt). To allow this, run WinSCP using console interface tool, WinSCP3.com
(you can find WinSCP3.com
in the main installation package).
Running Script under Different Account
If you are going to run the script under different account (for example using Windows scheduler), note that WinSCP stores configuration to user part of Windows Registry by default. So you may need either to transfer the configuration from your account registry to the other account registry or use INI file instead.
Advertisement
Example
The example below connects to example.com
server with account user
, downloads file and closes the session. Then it connects to the same server with account user2
and upload the file back.
option batch on option confirm off open user@example.com cd /home/user option transfer binary get examplefile.txt d:\ close open user2@example.com cd /home/user2 put d:\examplefile.txt close exit
Save the script to file example.txt
. To execute the script file use following command. As the script connects the session itself, using command open
, omit the session
command-line parameter.
winscp3 /console /script=example.txt
If you want to first open a session
that you have saved via the GUI, then add the name of you session as below.
winscp3 /console /script=example.txt saved_session
Now you can omit the open
command in your script file because you are now connected.