Mirror/Backup from SSH/SFTP to Windows

7

2

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?

Andrew Russell

Posted 2010-05-07T07:49:28.717

Reputation: 1 535

Answers

8

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

user1686

Posted 2010-05-07T07:49:28.717

Reputation: 283 655

1Worked 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 – 2010-05-10T01:29:45.920

1

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

russellpierce

Posted 2010-05-07T07:49:28.717

Reputation: 228

0

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.

OuzoPower

Posted 2010-05-07T07:49:28.717

Reputation: 184

0

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

Brian

Posted 2010-05-07T07:49:28.717

Reputation: 1 009

My impression is that rsync also needs to be installed on the server I am connecting to? Is this correct? – Andrew Russell – 2010-05-09T01:24:45.627

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 – 2010-05-10T15:05:10.187

hmm and I guess rsync is then running privileged and so I can access even root only files using rsync? – stefan.at.wpf – 2012-07-11T16:13:00.313

@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 – 2012-07-11T19:10:14.670

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 – 2012-07-14T05:50:00.433

... unless you have large files that you are transferring for which a smallish proportion of the file actually changes. – russellpierce – 2012-07-14T05:52:00.103