SCP is used to copy files across a network to another computer
while they do the same task SCP has some advantages 1. SCP is intereactive, SFTP is not. 2. SCP is faster than SFTP both use the ssh protocol
at the basic level use the following command
scp [option] [local-file-path] [user@remote-ip:dest-path]
options are
-C: Used to enable compression.
-i: Used to specify the private key file for authenticating a remote system.
-l: Used to limit the bandwidth for transferring files.
-P: Used to specify the SSH port to connect to the remote host.
-p: Used to preserve modification times and access times from the original file.
-r: Used to copy entire directories recursively.
-v: Used to print debugging messages.
To copy a single file from the local system to the /opt directory on the remote system, run the following command:
scp file1.txt user@remote-ip:/opt/
To copy multiple files from the local system to the /opt directory on the remote system, run the following command:
scp file1.txt file2.txt user@remote-ip:/opt/
To copy /etc., and all of its sub-directories recursively from the local system to the /mnt directory on the remote system, use the option -r with SCP as shown below:
scp -r /etc user@remote-ip:/mnt/
If you want to transfer a very large file and limit the bandwidth usage, you can use the -l option to limit the bandwidth.
For example, copy a file named wordpress.tar.gz to the remote system and limit the bandwidth for the SCP process to only 50 KB/sec. Then, you can use the parameter -l and set it to 50 x 8 = 400, as shown below:
scp -l 400 wordpress.tar.gz user@remote-ip:/opt/
SCP also allows you to copy files and directories from the remote to the local system.
To copy a file named /etc/resolv.conf from the remote system to the /mnt directory on the local system, run the following command:
scp user@remote-ip:/etc/resolv.conf /mnt/
If you want to preserve files modification and access times, you can use the -p option with the SCP command:
scp -p user@remote-ip:/etc/resolv.conf /mnt/
If your remote SSH server is listening on a port other than the default 22, then you can use the option -P to specify the port:
scp -P 2222 user@remote-ip:/etc/resolv.conf /mnt/