This is an old revision of the document!

Scripting/Automation

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

Advertisement

Příkazy

program akceptuje následující příkazy : call, cd, chmod, close, exit, get, help, keepuptodate, lcd, lls, ln, lpwd, ls, mkdir, mv, open, option, put, pwd, rm, rmdir, session, synchronize a různé aliasy Příkaz help <prikaz> zobrazuje komplexní popis prikazu zadaného do povelu zahrnujícího příkladdy a aliasy.

Multiple sessions can be opened simultaneously. Use the session command to switch between them. Commands can be read from a script file or passed from the command-line using the /command switch.

By default interactive mode is used (the user is prompted in the same way as in GUI mode). To switch to batch mode (all prompts are automatically answered negatively) use the 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).

Note also that the first connection to an SSH server requires verification of the host key, which cannot be automated by scripting. Therefore, some provision for accepting keys must be made prior to running the script to connect to a new host. Never attempt to make the script verify the host key automatically.

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 the exit code 0.

The Console Interface Tool

As WinSCP3.exe is a GUI application, it cannot inherit the console window when run from another console application (such as the Windows command-prompt). To allow this, run WinSCP using the console interface tool WinSCP3.com (you can find WinSCP3.com in the main installation package).

Running a Script under a Different Account

If you are going to run the script under a different account (for example using the Windows scheduler), note that WinSCP stores its configuration to the user part of Windows Registry by default. So you may need to either transfer the configuration from your account registry to the other account registry or use the INI file instead.

Advertisement

Note that the configuration also includes verified host keys, which you may need to transfer as well (or confirm manually under the account) to allow automatic execution of the script.

Příklad

Příklad uvedený níže se připojuje k serveru example.com s uživatelským účtem user, stáhne soubor a ukončí spojeni. Pak se připojí ke stejnému serveru jako uživatel user2 a nahraje soubor zpět.

# automaticky odpovídej na vše negativně bez zastavení na chybách skriptu
option batch on
# potlač přepis potvrzení, které jsou v rozporu s dřívějšími
option confirm off
# Připojení s použitím hesla
# open user:password@example.com
# připojení
open user@example.com
# Změň vzdálenou složku 
cd /home/user
# Vynuť si binární přenos
option transfer binary
# Stahni soubor do lokální složky na d:\
get examplefile.txt d:\
# Odpojení
close
# Připoj se jako jiný uživatel
open user2@example.com
# Změn vzdálený adresář
cd /home/user2
# nahraj soubor do pracovního adresáře
put d:\examplefile.txt 
# odpoj se
close
# konec WinSCP
exit

Ulož skript do souboru example.txt. K provedení skriptu použij následující příkaz. Skript se připojí k sezení sám, příkazem open, bez použití parametru příkazového řádku session .

winscp3 /console /script=example.txt

Místo použití příkazu open ve skriptu, lze otevřít sezení příkazem command-line parameter.

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

Last modified: by 212.96.164.161