Schedule Automatic Transfers

Run WinSCP transfers and backups automatically with Windows Task Scheduler.

By the WinSCP Downloads Team · Last updated

What do you need?

A WinSCP script that does the transfer, tested by hand from the command line, and the full path to winscp.com, which is installed next to WinSCP.exe (for example in C:\Program Files (x86)\WinSCP).

How do you write a script that works unattended?

A scheduled task often runs under a different Windows account and has none of your saved WinSCP settings. Make the script self-contained: give the host key and the key file in the open command, and run it with /ini=nul so it never depends on saved configuration.

open sftp://backup@example.com/ -privatekey="C:\keys\backup.ppk" -hostkey="ssh-ed25519 255 SHA256:..."
synchronize local /var/backups C:\backups
exit

Test it exactly as the task will run it:

"C:\Program Files (x86)\WinSCP\WinSCP.com" /ini=nul /script=C:\scripts\backup.txt /log=C:\scripts\backup.log

How do you create the scheduled task?

  1. Open Task Scheduler and choose Create Basic Task.
  2. Give the task a name and choose a trigger, for example Daily at 02:00.
  3. Choose Start a program. As Program, enter the full path to WinSCP.com.
  4. As Arguments, enter /ini=nul /script=C:\scripts\backup.txt /log=C:\scripts\backup.log.
  5. Finish, then open the task's Properties and select Run whether user is logged on or not.
  6. Right-click the task and choose Run to test it straight away.

How do you know whether it worked?

winscp.com returns exit code 0 when every command succeeded and 1 when one failed. Task Scheduler shows it as Last Run Result (0x0 means success), and the log file shows exactly which command failed and why.

Why does the script work by hand but fail in Task Scheduler?

  • The host key is not known to the task's account: add -hostkey to the open command.
  • The script relies on a saved site or settings from your own account: use /ini=nul and put everything in the script.
  • A path is relative: use full paths for the script, the log, the key file and local folders.
  • The account cannot read the key file or write the log folder: check its permissions.

Sources

This guide is written in our own words and checked against the official WinSCP documentation. For full details, see:

Related pages

Part of the WinSCP documentation. Download WinSCP for Windows.