To rsync a file or directory that contains spaces, you must escape both the remote shell and the local shell. I tried doing one or the other and it never worked. Now I know that I need to do both!
So lets say I’m trying to rsync a remote directory with my local machine and the remote directory contains a space (oh so unfortunately common with Windows files). Here’s what the command should look like:
rsync 'firstname.lastname@example.org:/path/with spaces/' /local/path/
The single quotes are used to escape the space for my local shell and the backslash is used to escape the remote shell.