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'
Best Answer
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:
This will copy both
file1
andfile2
fromexample.org
to the local directory.Your local
scp
program connects to the remote host and starts another instance of ofscp
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:
This works without problem, it transfers multiple source files over the network.
When using it as sink:
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):
And FWIW,
scp foo 'me@example.org:"foo bar"'
works just as well.