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@'s password:
debug1: Authentication succeeded (password).
Authenticated to ([]: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

  • Could you edit your question to clarify how you're running the scp command? The command that you've presented isn't valid, notably the space before the colon. Also, what ssh software (and specifically, what scp program) is being used on the remote server? – Kenster Jan 23 '18 at 15:51
  • The scp command is scp -v user@xxx.xxx.xxx.xxx:/local/file/path /destination/path Their is no space in between and I am sure about that. Remote server is based on InterNiche stack. – user7345878 Jan 23 '18 at 16:18
  • @user7345878 I have updated my answer, have a look at it. It goes through great detail to show how varíous scp programs perform the SCP exchange in their individual ways. You still did not say, what scp you were using, albeit it very much looks like it is of OpenSSH origin. – mvw Jan 24 '18 at 7:56

The short answer is that the scp software on the remote system seems to be sending an invalid protocol message. You should contact the software vendor for support.

Sink: C0777 630 /home/random/sample.txt
error: unexpected filename: /home/random/sample.txt

The "sink" message isn't an error. It's just a message giving an SCP protocol command received from the remote system. You're getting the "sink" message because you're running scp in verbose mode. This particular message indicates the remote system is sending a file ('C') with permissions 0777, size 630 bytes, and filename "/home/random/sample.txt".

The "error" message is indicating a problem with the SCP protocol command. The problem is that the OpenSSH scp program, which you're using for the local end, doesn't accept a filename containing a '/' character.

Here's what happens when I run a similar scp command:

$ scp -v localhost:/etc/services .
debug1: Sending command: scp -v -f /etc/services
Sending file modes: C0644 677972 services
Sink: C0644 677972 services

Note that the filename part in the "sink" line isn't a complete pathname, just the base name of the file being sent.

You indicated the remote system is running SSH software from InterNiche. You should contact this company for support. There's no formal standard for the SCP protocol that I'm aware of, and it's difficult to even find a good description of the protocol on the Internet. I think it's fair to say that most people would consider the OpenSSH version of scp to be the de facto standard, and would expect other scp implementations to interoperate with OpenSSH.

  • I am confused why scp and pscp behaves in different manner with the same server and same command syntax, arguments. – user7345878 Jan 24 '18 at 7:12

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, BSD rcp and Putty pscp (see below) it seems it is normal that one has to wade through the sources to understand SCP. This archived web page says:

Have you ever wondered how the scp and rcp commands worked? The first time I did I haven't found any documentation on the subject. There is no RFC, no draft, not even README file describing it. After reading the source code I tried again and realized that old version of rcp.c might be really the only original documentation available.

(Jan Pechanec's weblog: "How the SCP protocol works", copy from Februay 15, 2017)

Using the explanation from above's page and your command

scp -v user@xxx.xxx.xxx.xxx:/local/file/path /destination/path

It means you copy stuff from the remote system (InterNiche scp, which is in "source" mode) to your system (likely OpenSSH scp, in "sink" mode).

However the remote system gives you paths over several directories during the exchange under SCP protocol:

C0777 630 /home/random/sample.txt
<data of sample.txt>

while your scp can only deal with something like:

D0755 0 home
D0755 0 random
C0777 630 sample.txt
<data of sample.txt>

The solution is to check for a different scp implementation on your local system, or try sftp instead:

sftp -q user@xxx.xxx.xxx.xxx:/remote/file/path /local/destination/path

My inital answer, updated later:

Sink: C0777 630 /home/random/sample.txt

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.

if (verbose_mode)
    fmprintf(stderr, "Sink: %s", buf);

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 BSD rcp command, see the header

 * scp - secure remote copy.  This is basically patched BSD rcp which
 * uses ssh to do the data transfer (instead of using rcmd).

and line 1023.

This one

error: unexpected filename: /home/random/sample.txt

is written by line 1051:

if ((strchr(cp, '/') != NULL) || (strcmp(cp, "..") == 0)) {
    run_err("error: unexpected filename: %s", cp);

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 remote ssh instance.


Sink is the counter part to the Source call. Here we have the other side from the OpenSSH implementation:

    snprintf(buf, sizeof buf, "C%04o %lld %s\n",
        (u_int) (stb.st_mode & FILEMODEMASK),
        (long long)stb.st_size, last);

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.x rcp 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.

  • Ok, but what could be the error from the server side? How can I avoid this error? If it is an remaining buffer then where the files are getting copy, how can I assure the command failed or passed. Well I am sure that command failed because couldn't find the file on local system – user7345878 Jan 23 '18 at 15:35
  • To clear out this doubt, I issue pscp command like pscp -v -scp user@xxx.xxx.xxx.xxx:/remote/path /dest/path but this command copied the file successfully from remote server. – user7345878 Jan 23 '18 at 15:48
  • That looks like a mystery, because in original command I have not given any space in between colon and remote source file name. – user7345878 Jan 23 '18 at 16:15
  • @user7345878 I added a link to the source code of pscp which shows that it implements the SCP protocol different than OpenSSH scp. So that question is solved as well. – mvw Jan 24 '18 at 7:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.