88

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 ?

JamesThomasMoon
  • 752
  • 1
  • 6
  • 18
bob
  • 983
  • 1
  • 6
  • 6
  • 2
    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 Sep 12 '18 at 11:11

3 Answers3

136

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 [email protected]:"/file\\ path\\ with\\ spaces/myfile.txt"
Iulian Onofrei
  • 312
  • 5
  • 17
Atnaize
  • 1,504
  • 1
  • 11
  • 11
18

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" [email protected]:"'/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
  • 281
  • 2
  • 4
1

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/"

Code42
  • 197
  • 1
  • 2
  • 10