James Galley

Web application developer

PHP, Yii, MySQL, Node.js - JavaScript, HTML, CSS & SASS - Linux, AWS & serverless

Common rsync examples for MacOS and Linux

Rsync is a handy utility for transferring files on MacOS and Linux filesystems, to and from remote servers and local machines.

For example, if you wanted to download a backup file from a Linux server, you could use rsync to transfer that file to your local machine, using SSH with Public Key authentication.

Here's some of my commonly-used rsync examples for quick reference.

Download a file with rsync

Download a file from a remote server to a local machine, with SSH key authentication:

rsync -Pav -e "ssh -i $HOME/.ssh/key.pem" username@hostname:/path/to/source/file.ext /path/to/local/destination/

Problems with rsync

error in rsync protocol data stream (code 12)

I've typically seen this error when downloading files from a remote server, where the remote server doesn't have rsync installed. This is common on AWS Lightsail LAMP stack instances.

For my use-case in AWS Lightsail I was able to install Rsync using

sudo apt-get install rsync