Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Anyone who's ever SCP'd knows that this probably doesn't work:

scp foo.txt 'me@remote.net:foo bar.txt'

For me on this one, I get: "ambiguous target".

The man page for SCP doesn't explain why you need to escape that space, yet the argument seems to fit the specification for that argument listed in the man page:

[[user@]host1:]file1 

Seems to match, to me. So, why is it required to do this:

scp foo.txt 'me@remote.net:foo\ bar.txt'
share|improve this question
add comment

1 Answer

up vote 9 down vote accepted

In the first case, you are specifying two files as copy target, both residing on remote.net. This is clearly ambiguous, as the program cannot determine where to copy the file.

Consider the following, working example specifying two source files and one destination (directory) using the same format:

scp 'me@example.org:file1 file2' .

This will copy both file1 and file2 from example.org to the local directory.


Your local scp program connects to the remote host and starts another instance of of scp with a parameter determining whether you're transferring files from it (-f), or to it (-t). You can see this when you add the argument -v for verbose output. The source/destination parameter you enter (host:file) is split and the file names part simply appended as additional parameters specifying the files to use.

When using it as source:

debug1: Sending command: scp -v -f -- file1 file2

This works without problem, it transfers multiple source files over the network.

When using it as sink:

debug1: Sending command: scp -v -t -- file1 file2

This fails, as you're intending to write to multiple files. Now the way around this is to escape the file name again (once for the local shell, once for the remote call):

$ scp foo 'me@example.org:foo\ bar'
[...]
debug1: Sending command: scp -v -t -- foo\\ bar

And FWIW, scp foo 'me@example.org:"foo bar"' works just as well.

share|improve this answer
    
When viewing the verbose output it's obvious that this is much more efficient than the otherwise equivalent scp me@example.org:file1 me@example.org:file2 . –  Daniel Beck Feb 11 '13 at 23:18
    
Seems to me that the SCP man page ought to use "files", if more than one can be specified. There is a curious ..., and that might indicate more than one file, but I took it as "more stuff in other arguments" and opposed to "more stuff in this argument". –  Thanatos Feb 11 '13 at 23:45
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.