When I try to scp a file with a slash in its path, the path is quoted for the local host, and the last path component is additionally quoted for the remote host, like scp host:"a/b/'c'" .
, it fails with
protocol error: filename does not match request
unless I use the -T
option. However, if any other path component is quoted, like scp host:"a/'b'/c" .
, it works. Also, if the path is not quoted for the local host, like scp host:a/b/'c' .
, it works.
The man page documents -T
as:
Disable strict filename checking. By default when copying files from a remote host to a local directory scp checks that the received filenames match those requested on the command-line to prevent the remote end from sending unexpected or unwanted files. Because of differences in how various operating systems and shells interpret filename wildcards, these checks may cause wanted files to be rejected. This option disables these checks at the expense of fully trusting that the server will not send unexpected filenames.
I don't understand how this description explains the behavior I see. What is the rationale for scp's behavior? And is there any way to disable this "feature"?
I am running Ubuntu 16.04 and the remote host is running Ubuntu 12.04.
a/b/c
which will be copied to./c
on your local system. A filec
does not match your pattern"'c'"
. You disable the check with option-T
. If you quote the directory'b'
you will get a file namedc
irrespectively how the remote system interpretsa/'b'
. As the transferred file matches the specified pattern you don't need-T
.'c'
toc
. But it is terribly inconvenient.scp host:"a/b/'c'" .
? A filec
? A file'c'
with single quotes in its name?a/b/'c'
to pass to the remote shell and the remote shell to interpret it as filec
in foldera/b
. In other words, the file names stored in the filesystems on the remote and local hosts would both bec
. So ideally there would be no error without-T
. And the localscp
knows that it specified'c'
and got backc
. But it might not know that the two are the same in the respective filesystems.cp "a/b/'c'" .
thecp
command would try to copy a file'c'
because the inner single quotes are quoted by the outer double quotes. Your expectation howscp
should interpret your strange file name might be confusing for others (for the authors ofscp
).