Using scp with spaces in the file path

I just recently learned how to upload a file from my linux box to my webserver using scp the other day. Normally its pretty straightforward to use scp to upload or download a file to a server, however I was having the hardest time uploading this one file that had spaces in the file path.

Here is what it looked like:

scp -r /home/username/Desktop/Sysadmin\ Tools/sysadmin-tools.zip user@website.com:public_html/somefolder/

When i would run this command, the following error would be displayed:

zip warning: name not matched: /home/username/Desktop/Sysadmin
zip warning: name not matched: Tools/*

As you can see, it was breaking up the file path at the space in “Sysadmin Tools” folder, and breaking it up into different arguments. The solution to this problem is to do the following:

Solution:

scp -r /home/username/Desktop/Sysadmin\\ Tools/sysadmin-tools.zip user@website.com:public_html/somefolder/

All I needed to add was an extra “\” backspace character after “Sysadmin”. This is because when the file is uploaded to the remote server, the “\” escape character will disappear (I am not sure why), and will cause this kind of error. However if you double escape the space “\\”, the first escape character will be removed but the second will remain, thus keeping the correct file path.

References:

http://www.thingy-ma-jig.co.uk/blog/14-05-2007/how-to-scp-a-path-with-spaces

  • Share/Bookmark

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

Leave a Comment

Your email is never published nor shared.

(required)
(required)