scp copy has error "ambiguous target"

44

6

I try to copy files from a linux (ubuntu) machine to an external hard drive mounted on a mac but got an error message :

scp: ambiguous target

What I did is, I'm on a mac, ssh to the linux machine where files are. Then use the following command :

scp fileToCopy myMacUser@myMacMachine:/Volumes/MyExternalDrive/targetDirectory

What did I do wrong ? What is the good command to use in this case ?

bob

Posted 2016-01-07T09:16:03.747

Reputation: 543

Happened to me when I had an extra param (-t; a remnant from a previous ssh command) in the arg list; apparently it is not supported by scp but the error I got was ambiguous target :( – Janaka Bandara – 2018-09-12T11:11:07.417

Answers

69

If you have white space in a path, you have to escape the characters by using double backslashes \\ and enclosing the entire path in quotes:

scp myfile.txt user@192.168.1.100:"/file\\ path\\ with\\ spaces/myfile.txt"

Atnaize

Posted 2016-01-07T09:16:03.747

Reputation: 834

4yes, that is it ! I first tried with double \ but didn't work and then I tried adding " " around my path with \. That does the job. Thanks. – bob – 2016-01-07T09:33:20.753

I have to look this up every time! the error message should say you have to escape spaces 3 times... – codenamejames – 2018-05-08T02:10:55.680

1Wrapping the remote path in quotes was key for me – sam452 – 2018-07-23T19:45:21.607

2Single quotes and single backslashes works just as well. – andrew lorien – 2018-11-19T07:44:40.190

2Triple backslashes without quotes works also. – pizzapants184 – 2018-12-17T20:49:02.533

3Double quotes in single qoutes without escaping spaces also work (scp myfile.txt user@192.168.1.100:'"/file path with spaces/myfile.txt"'). In fact you must escape the filename twice: first time from the local shell, and second time from the remote one. – mik – 2019-07-19T14:00:09.253

Per @sam452 key is to wrap ONLY THE REMOTE TARGET in quotes. Wrapping the local file kept giving me "no such file or directory" errors – JoelAZ – 2019-10-24T00:53:55.300

0

You need to put quotes so that spaces won't be misinterpreted. Instead of doing scp file Server:/folder\ location/ you should do scp file "Server:/folder\ location/"

Dr_Hope

Posted 2016-01-07T09:16:03.747

Reputation: 133

0

I found that two sets of quotes worked for me, around the target location. Double quotes outside, and single quotes inside the double quotes. For example:

scp "my local file.txt" user@192.168.1.100:"'/folder/my spacey folder name/'"

The outside set of quotes are for the local shell, and the inside quotes are for the remote shell. Thanks to @mik for the suggestion in comments.

kristianp

Posted 2016-01-07T09:16:03.747

Reputation: 101