Upload to multiple servers / Parametrized script

If you need to repeat the same task against multiple servers, instead of writing separate and almost identical scripts for each server, you can write one parametrized script.

Following example is parametrized script that accepts one parameter with session URL and uploads a fixed local file to a fixed remote directory:

open %1%
put examplefile.txt /home/user/
exit

Advertisement

To use the script against multiple servers, just execute the script (saved to file script.txt) repeatedly, using different session URL as parameter:

winscp.com /script=script.txt /parameter sftp://martin@server1.example.com/
winscp.com /script=script.txt /parameter sftp://test@server2.example.com/

If the script has also other variable parts, like file to upload or remote directory, just replace those parts with additional parameters (%2%, %3%, etc).

Alternative to using /parameter switch is using environment variable in the script.

Further Reading

Last modified: by martin