Sync Folders with WinSCP

Keep a local folder and a server folder in sync, by hand or automatically.

By the WinSCP Downloads Team · Last updated

Which direction should you sync?

  • Remote: makes the server folder match your local folder. Use it to publish a website or upload a project.
  • Local: makes your local folder match the server. Use it to back up or download changes.
  • Both: copies newer files in each direction. It never deletes files, so removed files must be deleted on both sides by hand.

How do you sync folders in the WinSCP window?

  1. Connect to the server and open the local and remote folders you want to sync.
  2. Choose Commands > Synchronize.
  3. Choose the direction: Remote, Local or Both.
  4. Choose the mode: Synchronize files (copy newer files), Mirror files (also replace newer files with older ones) or Synchronize timestamps.
  5. Tick Delete files if files removed from the source should also be removed from the target, and tick Preview changes.
  6. Review the synchronization checklist, untick anything you do not want, and start.

Comparison criteria decide what counts as changed: modification time, file size, or both. Size-only comparison helps when the two computers' clocks or time zones differ.

How do you keep a folder up to date automatically?

Commands > Keep Remote Directory up to Date watches a local folder and uploads every file you save, while WinSCP stays open. It is the quickest way to work on a website locally and see each change on the server straight away.

How do you sync from a script?

The synchronize command does the same thing unattended. Start with -preview to see what would change without changing anything:

open sftp://user@example.com/ -hostkey="ssh-ed25519 255 SHA256:..."
synchronize remote -preview C:\site /var/www
exit

When the preview looks right, remove -preview. Add -delete to remove files that no longer exist locally, -mirror to also replace newer files, or -criteria=size to compare by size only:

synchronize remote -delete C:\site /var/www
synchronize local -criteria=size /var/backups C:\backups

In both mode, -delete and -mirror are ignored: two-way synchronization never deletes files.

What should you check before deleting files?

Delete files and -delete remove anything on the target that is not on the source. Point them at the wrong folder and they can delete a whole site or backup. Always preview first, and double-check both paths, especially in scripts.

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.