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.