SSH and file Transfers
The biggest lie is that: ssh doesn't do file transfer. The core of SSH described in the previous article is used to make a connection, authenticate, and create a subchannel.
Note that a file transfer program in a Unix-based system, scp or sftp, doesn't have ssh implemented within them. The file transfer program runs SSH in a sub-process to connect to the host machine.
Scp is just rcp, but instead of calling rsh to connect to the host, it uses ssh to make the connection.
What is rcp(remote copy protocol)?
rcp is very limited; it can only transfer a whole file in one direction; no directory browsing, partial transfer, resumption of interrupted transfer, and multiple transfer direction in a single session.
sftp: The postman pro max ultra
A better implementation of scp was done to be a reliable, secure duplex byte-stream connection over the SSH2: the sftp. Later on, the sftp was moved onto the standards track of the IETF SECSH working group as the "SSH File Transfer Protocol" (SSH-SFTP).
Note that sftp can't connect securely to an FTP server as SSH and FTP are incompatible.
A summary of the file transfer program
rcp: copy a file by using a connection established by RSH
scp: more like rcp(remote copy protocol) but use SSH for connection
sftp/scp2: much better file transfer protocol specified in the SSH-2 version and implemented in OpenSSH and tectia
FTP: move a file to another FTP server through TCP/IP
scp details
When a client runs an scp command, the remote server also runs an scp command; it invokes a switch, -t and -f( to and from).
This client scp command: Runs this remote command:
scp for server:bar scp -t bar
scp server:bar foo scp -f bar
scp *.txt server:dir scp -d -t dir
If an scp is run between two remote hosts, the source host runs an scp to copy the file to the target, as shown below.
scp source:music.au target:playme
runs this in the background:
ssh -x -o ClearAllForwardings=yes -n source scp music.au target:playme
Note that the options are changed appropriately: agent forwarding is not turned off, as the remote scp client may need that to contact the target host.
Scp2/sftp details
ssh [options] server-host -s sftp
The scp2 or sftp runs an ssh program in the background. It hides the client details on how the stfp is implemented on the server. no pathname or file name is specified; these informations are carried inside the sftp protocol
Configuration
To use sftp, ssh must be configured:
For OpenSSH:
# sshd_config
subsystem sftp /usr/libexec/sftp-server
Tectia can either execute an external SFTP server in the same way:
# sshd2_config
subsystem-sftp /usr/libexec/sftp-server2
or run the SFTP protocol within the SSH server process itself:
# sshd2_config
subsystem-sftp internal://sftp-server