Search code examples
network-programmingsftpfile-transferscp

How is SCP (secure copy protocol) file transfer working?


Please, tell me how does the SCP work.

Can anybody explain(or show) SCP file transfer to me (something looks like picture, flow or reference).
What were the differences between SCP and SFTP file transfer?

Thanks in advance, and sorry about my language.


Solution

  • The SCP client connects to the SSH server and executes scp command there. In most cases, the remote scp would be the OpenSSH scp command. That means, if you use the OpenSSH scp command as a client, the local scp (as a client) actually talks to the same program on the server. The remote scp is executed with undocumented -t (to) or -f (from) flags. This way, the scp program recognizes that it serves as a server.

    Once the remote scp is running, it talks with the local SCP client (the scp or another implementation) using a simple protocol.

    An SCP command is one-letter followed by some arguments and new-line.

    An SCP response is one byte, with 0x00 = ok, 0x01 = error, 0x02 = fatal error (though the OpenSSH scp actually never responds with 0x02). The error code is followed by an error message (terminated with a new-line).

    It's always the source side that feeds the commands. The target side consumes them. I.e. when downloading, the server feeds the commands and the client consumes them. When uploading, the client feeds the commands and the server consumes them.

    Commands are:

    • E – exit
    • T – sets timestamps for the upcoming file
    • C – file transfer
    • D – directory

    See also Explanation for SCP protocol implementation in JSch library.