I am trying to copy a file from my local host to remote host using SCP command:
scp -v user@xxx.xxx.xxx.xxx:/local/file/path /destination/path
Surprisingly the SCP command fails at the end after password authentication. I am able to do SSH to remote system but SCP fails. Here is the error which I got at the end.
debug1: rekey after 4294967296 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 4294967296 blocks
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: password
debug1: Next authentication method: password
admin@192.168.1.12's password:
debug1: Authentication succeeded (password).
Authenticated to 192.168.1.12 ([192.168.1.12]:22).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: pledge: network
debug1: Sending command: scp -v -f /home/random/sample.txt
Sink: C0777 630 /home/random/sample.txt
error: unexpected filename: /home/random/sample.txt
What is the cause of failure, I have verified that the source file exists. I am not able to understand what's this error message Sink: C0777 630
Best Answer
Your remote side implements the SCP "protocol" in a way, which is not compatible to the OpenSSH implementation of
scp
which you will find typically on a Linux or BSD machine.After reading through code from OpenSSH
scp
, BSDrcp
and Puttypscp
(see below) it seems it is normal that one has to wade through the sources to understand SCP. This archived web page says:Using the explanation from above's page and your command
It means you copy stuff from the remote system (InterNiche
scp
, which is in "source" mode) to your system (likely OpenSSHscp
, in "sink" mode).However the remote system gives you paths over several directories during the exchange under SCP protocol:
while your
scp
can only deal with something like:The solution is to check for a different
scp
implementation on your local system, or trysftp
instead:My inital answer, updated later:
It seems to originate from
scp
.E.g. you can have a look at line 969, which is a recent version of OpenSSH used by FreeBSD.
Translation: If in verbose mode then display the "Sink:" message, with the string pointed to by
buf
You provided the -v option.It seems to display the remaining buffer.
C0777
seems to be a BSDrcp
command, see the headerand line 1023.
This one
is written by line 1051:
Translation: if the string pointed to by
cp
contains a slash (/
) character or is equal to the string..
then print the error message. Your string features a slash.It seems that
scp
is not getting what it expects from its conversation with the remotessh
instance.Update:
Sink
is the counter part to theSource
call. Here we have the other side from the OpenSSH implementation:From the code before it is clear that these three arguments are the file mode (permission bits), file size and file name. Again the file name is not allowed to contain a slash, otherwise it is ignored.
It looks like a directory tree is recursively walked and only the name of the walked level is handled.
By the way, the code in OpenSSH
scp
seems really old, the cited stuff is already in the BSD 4.xrcp
implementation. See here.Having a look at the
pscp
implementation (Putty scp) here we can recognize the BSD stuff (see around line 1524), but the filename handling is different. That is why it works.