What I am trying to do is mirror a directory (recursively) from a server I can SSH/SFTP to, to a Windows machine. I want to do this as part of a script, so it can be automated.

I only want to copy new or modified files. I don't want to have to download all the files every time the script runs.

In other words, I'm trying to get the equivalent of RoboCopy /MIR that will work using SFTP as a source.

What would you recommend?


WinSCP can synchronize directories using /synchronize or with a script.

| improve this answer | |
  • 1
    Worked for me, thanks. The command I used: "C:\Program Files (x86)\WinSCP\WinSCP.com" My_Stored_WinSCP_Session /command "synchronize local X:\Local\Target\Directory /the/remote/directory" exit – Andrew Russell May 10 '10 at 1:29

Mount your SFTP server as a drive using SFTPNetDrive then robocopy as regular (probably with /Z).

| improve this answer | |

If you only want to get the files that have changed, I would recommend rsync (under cygwin).

| improve this answer | |
  • My impression is that rsync also needs to be installed on the server I am connecting to? Is this correct? – Andrew Russell May 9 '10 at 1:24
  • Yes, rsync would need to be installed on the server as well. When given a remote file path, it will connect via SSH and run and rsync daemon on the server. – Brian May 10 '10 at 15:05
  • hmm and I guess rsync is then running privileged and so I can access even root only files using rsync? – stefan.at.wpf Jul 11 '12 at 16:13
  • @stefan.at.wpf No, the rsync daemon runs as the user who connected by SSH. It would only have root privileges if root started it as a service on the server (and then you would use the rsync protocol to connect instead of SSH). But even in this mode, the rsync daemon can be configured to run as a less-privileged user. – Brian Jul 11 '12 at 19:10
  • For rsync to work well it needs to be installed in both locations. In my experience, rsync on Windows doesn't work so well. DeltaSync hides some of the cygwin. Unison does an even better job, but is overkill for what you are doing. – russellpierce Jul 14 '12 at 5:50

Although I must admit not having tested in the context of a SFTP connection, I would suggest FreeFileSync: https://www.freefilesync.org/manual.php?topic=synchronize-with-sftp

Not truly a script but a software with a graphical interface. It is very well designed, easy to use and runs on many operating systems.

It lets you recursively compare files and directories before synchronizing, with three comparison modes: file sizes, file dates+size, file content. You can also use filters to disable exclude some files or folders.

Preferably install the software from the command line as administrator with the /NOCANDY option to avoid ads. Alternatively, the Donation Edition is also ad-free: https://www.freefilesync.org/faq.php#donation-edition

There is a second software coming together, named RealTimeSync if you want to synchronize folders automatically.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.