Monday, May 28, 2007

scping files with spaces in them


nothing l33t...

but if you have to scp files with spaces in them and you dont do it right you can get a stupid

scp: ambiguous target

error, which can be quite unfun.

example:

scp "Other Linux 2.6.x kernel-cl1.vmdk" root@192.168.0.1:"Other Linux 2.6.x kernel-cl1.vmdk"
root@192.168.0.1's password:
scp: ambiguous target

The issue is that even though its in quotes scp is looking at it as "Other" as a file and "Linux" as a file..

here's the fix

scp Other\ Linux\ 2.6.x\ kernel-cl1.vmdk root@192.168.0.1:"Other\ Linux\ 2.6.x\ kernel-cl1.vmdk"
root@192.168.0.1's password:
Other Linux 2.6.x kernel-cl1.vmdk 100% 2043MB 10.9MB/s 03:07

you can also leave out the escape characters in the source files and just put the source file in quotes, but you'll need them on the destination file.

scp "Other Linux 2.6.x kernel-cl1.vmdk" root@192.168.0.1:"Other\ Linux\ 2.6.x\ kernel-cl1.vmdk"
root@192.168.0.1's password:
Other Linux 2.6.x kernel-cl1.vmdk 100% 2043MB 10.9MB/s 03:07

hope that helps someone :-)
CG

8 comments:

Henrik said...

Helped me ;) Thanks!

Anonymous said...

Helped me too! Thanks!

Anonymous said...

Very good one. Many thanks!

Anonymous said...

Thanks for this. I was so convinced that my ssh config was the problem, but it was just the spaces.

Anonymous said...

Thanks, fixed my problem

Anonymous said...

Thanks - that one was driving me crazy.

outspaced said...

Perfect - thanks!

Anonymous said...

Awesome. Thank you. I was going nuts!