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

If you found this post useful and would like to help support this site - and get something for yourself - sign up for any of the services listed below through the provided links.

The following links are part of affiliate programs, and I will receive a referral payment from any of the services you sign-up for.

  • Get Faster Shipping: About to order some stuff on Amazon but want to get more value out of the money you would normally pay for shipping? Sign-up for a free, 30-day trial of Amazon Prime to get free two-day shipping, access to thousands of movies and TV shows, and more.
  • Start Investing Now: Looking to start investing some of your saved income? Get started by opening an account with Webull, where upon sign-up and opening a brokerage account with an initial deposit of $100 or more you will receive free stock(s). The promotions are always changing, so be sure to click the link to see the latest.

Thanks for reading and take care.