Warning: count(): Parameter must be an array or an object that implements Countable in /home/mikestec/public_html/ubuntu-antenna/wp-content/plugins/wordpress-ping-optimizer/cbnet-ping-optimizer.php on line 533

scp: Ambiguous Target Error Solved

scp: Ambiguous Target Error

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 user@”/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 user@”/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 user@”/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.

  1. Kris
    • Mike Mike