How to copy files with rsync over SSH

Copy a file from local server to remote one:
rsync -v -e ssh /home/localuser/testfile.txt remoteuser@X.X.X.X:/home/remoteuser/transfer

In the above example we will copy a file called testfile.txt from the current server to the remote one and will place it inside the folder /home/remoteuser/transfer.

If the remote server is configured to work with non-default SSH port (other than 22) we can specify that inside the -e option:

rsync -v -e “ssh -p2222” /home/localuser/testfile.txt remoteuser@X.X.X.X:~/transfer

Again the testfile.txt will be copied inside the /home/remoteuser/transfer folder situated on the remote server.

Copy a file from remote server into a local folder:

rsync -v -e ssh remoteuser@X.X.X.X:/home/remoteuser/transfer/testfile.txt /home/localuser/

In the above example we will copy a file called testfile.txt from the remote server inside a local folder called /home/localuser/.

Synchronize local folder on remote server:

rsync -r -a -v -e ssh –delete /home/localuser/testfolder remoteuser@X.X.X.X:/home/remoteuser/testfolder

Synchronize folder from the remote server on the local server:

rsync -r -a -v -e ssh –delete remoteuser@X.X.X.X:/home/remoteuser/testfolder /home/localuser/testfolder
Source: How to copy files with rsync over SSH – Tutorials For Kyup.com

How to copy files with rsync over SSH was last modified: October 19th, 2018 by Jovan Stosic

Leave a Reply