ThorneLabs

Transfer Files and Directories Containing Spaces Using scp

• Updated January 21, 2019


If you have ever used scp to transfer files and/or directories containing spaces, you have problem encountered a lot of annoying errors.

Some of the errors encountered might look like the following:

[james@raxus] scp -r james@backup.example.com:/home/james/Pictures/London Trip/First Day .
scp: /home/james/Pictures/London: No such file or directory
scp: Trip/First: No such file or directory
scp: Day: No such file or directory

It’s rather annoying.

Your first thought is probably to escape the spaces in the file path:

[james@raxus] scp -r james@backup.example.com:/home/james/Pictures/London\ Trip/First\ Day .

But, nope. You’ll get the same errors:

scp: /home/james/Pictures/London: No such file or directory
scp: Trip/First: No such file or directory
scp: Day: No such file or directory

How about putting double quotes around the parts of the file path with spaces?

[james@raxus] scp -r james@backup.example.com:/home/james/Pictures/"London Trip/First Day" .

Again, nope. You’ll get the same errors:

scp: /home/james/Pictures/London: No such file or directory
scp: Trip/First: No such file or directory
scp: Day: No such file or directory

There are several options that do work, but the two options I find the most human readable, and easiest to remember, are the following.

The First Working Option

The first working option, and the one I prefer, is to put double quotes around the entire source target’s file path, and escape the particular parts of the source target’s file path containing spaces:

[james@raxus] scp -r james@backup.example.com:"/home/james/Pictures/London\ Trip/First\ Day" .

The Second Working Option

The second working option is to put single quotes around the entire source target, and put double quotes around the first part of the source target’s file path containing spaces to the very end of the source target’s file path:

[james@raxus] scp -r 'james@backup.example.com:/home/james/Pictures/"London Trip/First Day"' .

Some additional working options can be found at the link(s) in the References section.

References