Skip navigation.
Sponsors
Recent comments
How to SCP a path with spaces

How to SCP a path with spaces

14
May
2007

Baby Tux

I recently needed to remotely copy over SSH a folder from the remote machine to my local machine. Usually this is not a problem, however the path to this folder had a space in it. The folder itself is rather large and contains files which wouldn't really benefit from compression. It turns out the solution was quite simple.

These instructions are assuming you're connecting from a unix-like system to a unix-like system (eg Linux or OSX).

scp -r myserver.com:"/path/with/a/Space\\ In\\ It" ./

This basically says "recursively copy the folder at myserver.com (using the local username) to the current folder using scp". Now the spaces need to be double escaped as the first escape only signifies that they're spaces on the LOCAL machine - by the time they got to the remote machine, they wouldn't be escaped anymore. By double escaping them locally, by the time the path makes it to the remote machine they are just single escaped. I have to admit - I'm not 100% sure why you need the double quotes around the path itself.

Personally, I tend to run the scp command within a separate screen so I can detach it and reattach it later. It also means that if my connection from my machine to the machine I'm SSH'd to (be it local or remote) drops or crashes, the process will continue to run and I can reattach the screen when i reconnect.

thanks

Really appreciate stuff like this. Thank you very much

Thanks

Great but i am not sure if you need to escape the slashes.
But if it is then Thanks for the post.

Easier way?

This also worked for me, and it's easier if you have a filename with a lot of spaces in it:

scp user@host:"'file name with lots of spaces'"

Your local shell will ignore the outer double quotes and the remote shell will receive the filename in single quotes. You would probably have to do something else if the remote filename has " or ' characters.

want to download theems for my mobile

its very nice

It'd be nice if you asked before taking stuff from my site. Contact me at webmaster [at] thingy - ma - jig . co . uk

This site was based on the Cobalt 2.0 Theme for phpBB written by Jakob Persson

Search
Weblinks

Add to Technorati Favorites

TGC Webring

CMS Drupal Showcase

Feedburner for ThingyMaJig

View Nicholas Thompson's profile on LinkedIn

IconBuffet

Twitter

bile-edge