I was attempting to secure copy a file over a remote server and I encountered the following error:
$ scp file.txt user@ip_address:"/file path/"
scp: ambiguous target
So after some trial and error I discovered the problem was the space " " in the path to which I was attempting to copy the file to (despite having put the path within quotes).
To solve this problem you need to escape the space e.g.
$ scp file.txt user@ip_address:"/file\ path/"
thanks, exactly what i was looking for. Worked perfectly!
ReplyDeletethanks worked perfectly!
ReplyDeletetks a lot ... it just helped me with my mac and my hacked ATV...
ReplyDeleteGreat tip..
Thanks a lot! I have been fighting this for a couple of days. This is the best explanation I have found, and yes it worked!
ReplyDeleteI've been pulling my hair out over this, thanks man
ReplyDeleteYou will also get this error if you just escape spaces and DON'T quote.
ReplyDeleteSo you must quote and escape spaces.
I tried to scp files from cygwin to linux host via command:
ReplyDelete#ssh CYGWIN_HOST 'scp /root/test.txt root@LINUX_HOST:/root/test.txt'
scp: command error: Ambiguous target file.
It was fixed by:
#ssh CYGWIN_HOST 'DEST="/root/test.txt"; scp /root/test.txt root@LINUX_HOST:/root/test.txt'
U saved me thx !
ReplyDeleteHi, since this is in the top Google results, I thought I'd share that a more elegant way might be to add escaped nested quotes. Example:
ReplyDeletescp documents.zip remote:"\"/var/path/containing some spaces/foo/\""
Thanks so much! I had escaped the spaces as you describe, but I had not used the quotes!! Such a life saver, man!
ReplyDeleteThank you for the solution that helped even 7 years later :)
ReplyDeleteI've been stuck on this for quite a while... thanks a lot man!
ReplyDeleteThanks much ...It working perfectly
ReplyDeleteThanks much....It is working properly
ReplyDelete4 Years later and this post has just saved me so much frustration. THANK YOU.
ReplyDeleteGreat, thanks for this. Helped me out!
ReplyDeleteThis solved the problem instantly. Thank you.
ReplyDeleteI am trying the same but when i exit my putty session or putty session gets closed due to timeout, it stops scping. Also i do not see any jobs once i re-login. But if i do "ps -ef|grep scp" i can see the scp process there but it is hung as it is not scping anything.
ReplyDeleteAny suggestion in this case please ?
linux scp
The process will stop as soon as you exit putty. You will probably need to use nohup e.g. 'nohup [scp command] &'. Not really sure how your grep command returns the process (unless it is the grep command itself that it is finding?).
Delete