WinSCP scripts and batch files
Anything you do in WinSCP by hand can run unattended from a script. The classic pair is a script file (WinSCP commands) and a batch file that runs it and checks the result.

Let WinSCP write the script for you
- In the Login dialog select your site → Manage → Generate Session URL/Code.
- Choose the Script tab, format Batch file. WinSCP writes the exact
openline including the -hostkey fingerprint, so the script never stops to ask. - Or in Commander: select files → Transfer Settings → Generate Code for a ready
put/get.
backup.txt — the WinSCP script
open sftp://student@203.0.113.10/ -hostkey="ssh-ed25519 255 SHA256:LA+auhZNrl+orHphcUOZ/FeRoAg/7Au9Kh59b5OHm3w" -privatekey="C:\Users\you\.ssh\id_ed25519.ppk" lcd C:\work\site cd /home/student/site synchronize remote -delete -criteria=time get /var/log/app/*.log C:\work\logs\ exit
backup.bat — the runner
@echo off set WINSCP="C:\Program Files (x86)\WinSCP\WinSCP.com" %WINSCP% /ini=nul /log="C:\work\backup.log" /script="C:\work\backup.txt" if %ERRORLEVEL% neq 0 ( echo FAILED - see C:\work\backup.log ) else ( echo OK )
winscp.com(not .exe) is the console version for scripts.- Check the install path on your PC:
where /r "C:\Program Files*" winscp.com. /ini=nulignores your GUI settings so the script behaves the same on every PC.- Exit code 0 = everything succeeded. Anything else = read the log.
- A key with a passphrase cannot be typed by a scheduled job: run Pageant at logon, or use a separate key without a passphrase that is allowed only for this job (see next lesson).
Try it — first script
- Generate the open line for your lab site.
- Write a script that uploads
hello.txtand downloads/etc/os-release. - Run the batch file twice and read
backup.log; then break the host name and confirm you get FAILED.
Rating
0
0
There are no comments for now.
Join this Course
to be the first to leave a comment.