scp: Ambiguous Target Error
Recently I needed to copy a file using scp to another server and encountered the following error: “scp: ambiguous target” In doing some testing I figured out that the space in the file name was the problem. Here is how to handle a file name with a space in it.
I even tried putting the file name in quotes, and that didn’t take care of the ambiguous target error message. For example, I was trying to use the following command:
scp myfile.txt email@example.com:”/file path with spaces/myfile.txt”
In trying to put the quotations marks in several different places, it still didn’t work. What you need to do is escape the space with a backslash. what is meant by this is that you need to put a backslash in front of every space in the file path name. So the above command then becomes:
scp myfile.txt firstname.lastname@example.org:”/file\ path\ with\ spaces/myfile.txt”
This takes care of the scp: ambiguous target error message from the command line, but what about running inside a shell script. In that case, you would add two backslashes. So the above command then becomes:
scp myfile.txt email@example.com:”/file\\ path\\ with\\ spaces/myfile.txt”
This article was originally posted on www.mikestechblog.com Any reproduction on any other site is prohibited and a violation of copyright laws.