Copy Folders and/or Files with Rysnc and SSH from Desktop to Remote Server and Vice Versa
Posted: Sat Mar 14, 2020 3:31 pm
Rsync is a utility for efficiently transferring and synchronizing files between a computer and an external hard drive and across networked computers/servers by comparing the modification times and sizes of files. It is commonly found on Unix-like operating systems. Rsync is written in C as a single-threaded application, see more.
It is possible to use secure copy (scp) with the recursive option (-r) to transfer files/folders, for example, to move files from Desktop to the remote host/server:
or from the remote host to the Desktop:
But using rsync is very powerful because it enables you to resume transfers if the connection breaks accidentally, and it intelligently transfers only the differences between files. Therefore, we can use rsync to move files from local directory on the Desktop to the remote server as:
or do vice versa:
Note that in both cases be careful of trailing slashes: moving /path/to/local/dir to remote host /path/to/remote/dir/ results in /path/to/remote/dir/dir.
It is possible to use secure copy (scp) with the recursive option (-r) to transfer files/folders, for example, to move files from Desktop to the remote host/server:
- scp -r /path/to/local/dir user@remotehost:/path/to/remote/dir
or from the remote host to the Desktop:
- scp -r user@remotehost:/path/to/remote/dir /path/to/local/dir
But using rsync is very powerful because it enables you to resume transfers if the connection breaks accidentally, and it intelligently transfers only the differences between files. Therefore, we can use rsync to move files from local directory on the Desktop to the remote server as:
- rsync -avz -e 'ssh' /path/to/local/dir user@remotehost:/path/to/remote/dir
or do vice versa:
- rsync -avz -e 'ssh' user@remotehost:/path/to/remote/dir /path/to/local/dir
Note that in both cases be careful of trailing slashes: moving /path/to/local/dir to remote host /path/to/remote/dir/ results in /path/to/remote/dir/dir.