Mirror/Backup from SSH/SFTP to Windows
20,932
Solution 1
WinSCP can synchronize directories using /synchronize
or with a script.
Solution 2
Mount your SFTP server as a drive using SFTPNetDrive then robocopy as regular (probably with /Z).
Related videos on Youtube
Author by
Andrew Russell
Updated on September 17, 2022Comments
-
Andrew Russell over 1 year
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 about 14 yearsMy impression is that rsync also needs to be installed on the server I am connecting to? Is this correct?
-
Andrew Russell about 14 yearsWorked 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
-
user3418803 about 14 yearsYes, 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.
-
Polos almost 12 yearshmm and I guess rsync is then running privileged and so I can access even root only files using rsync?
-
user3418803 almost 12 years@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.
-
russellpierce almost 12 yearsFor 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 almost 12 years... unless you have large files that you are transferring for which a smallish proportion of the file actually changes.