PDA

View Full Version : scp and directories with spaces


claytex
03-30-2005, 03:20 PM
Sitting at my office computer, I want to copy some files from my home computer using scp. It works fine unless there are spaces in a directory.

This seems like it should work, with the backslash to escape the space:
$ scp username@00.00.00.00:/Users/username/Test\ Folder/testfile .
But i get:
scp: /Users/username/Test: No such file or directory
scp: Folder/testfile: No such file or directory
I took a couple of other stabs, using quote marks, that didn't work either:
$ scp username@00.00.00.00:"/Users/username/Test Folder/testfile" .
$ scp username@00.00.00.00:/Users/username/"Test Folder"/testfile .
Using another directory, with no spaces, this works:
$ scp username@00.00.00.00:/Users/username/TestFolder/testfile .
Is scp just not able to deal with spaces, or what?

Clay

vancenase
03-30-2005, 04:05 PM
try this
scp "username@00.00.00.00:/Users/username/Test\ Folder/testfile" .

claytex
03-30-2005, 04:12 PM
Yup, that works. Thanks a lot!

Clay

afb
03-30-2005, 08:03 PM
Also, if you have a passwordless login, you can tab-complete the remote path, and it should correctly deal with spaces (which adds 3 backslashes before each space, I think). Actually, you can do it without that, but then every tab asks for the password.

There are a (http://www.macosxhints.com/article.php?story=20040428100632295) number (http://www.macosxhints.com/article.php?story=20031217081557968) of (http://www.macosxhints.com/article.php?story=20031217081509218) hints (http://www.macosxhints.com/article.php?story=2003121708324421) on (http://www.macosxhints.com/article.php?story=20011207004643312) that (http://www.macosxhints.com/article.php?story=20011128174701140).

UltraNurd
04-02-2005, 12:38 PM
For the curious, there's a reason why you have to take this extra step to deal with spaces in paths on the remote system.

First, you're escaping spaces in the argument you're giving scp locally, so that it doesn't separate the path into multiple arguments.

Second, scp opens a shell on the remote system to access the file, which also needs the spaces escaped so that it can use the path correctly.

In general, I try to avoid spaces in paths where I expect to be doing a lot of work in a shell, just to save this step. However, if you make it a habit to always quote the path argument, and use tab completion when possible, the shell will take care of the first level of escaping for you.