This is an old revision of the document!

Scripting/Automation

See Command-line parameters to learn how to enter the console/scripting mode.

ssdadadadasda

Advertisement

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.

Note that the configuration also includes verified host keys, which you may need to transfered too (or confirm manually under the account) to allow automatic execution of the script. Never attempt to make the script verify the host key automatically.

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.

# Automatically answer all prompts negativelly not to stall
# the script on errors
option batch on
# Disable overwrite confirmations that conflict with previous
option confirm off
# Connect
open user@example.com
# Change remote directory
cd /home/user
# Force binary mode transfer
option transfer binary
# Download file to local directory d:\
get examplefile.txt d:\
# Disconnect
close
# Connect as different user
open user2@example.com
# Change remote directory
cd /home/user2
# Upload file to current working directory
put d:\examplefile.txt 
# Disconnect
close
# Exit WinSCP
exit

Advertisement

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

Instead of using open command you can also open session using command-line parameter.

winscp3 /console /script=example.txt user@example.com

Last modified: by 203.197.90.149