Recently we had to transfer some server. Server has so many images and size was in GB. So there was no option to download image through FTP and upload again. It was waste of resource and time. For that we applied SCP commands.
What is SCP?
SCP or secure copy allows secure transferring of files between a local host and a remote host or between two remote hosts. Linux SCP uses the same authentication and security as the Secure Shell (SSH) protocol from which it is based.
How to use SCP commands?
Copy file from local host to a remote host:
$ scp filename.txt username@to_host:/remote/directory/
Copy directory from local host to a remote host:
$ scp -r /local/directory/ username@to_host:/remote/directory/
Copy file from remote host to remote host:
$ scp username@from_host:/remote/directory/file.txt username@to_host:/remote/directory/
Copy file from a remote host to local host:
$ scp username@from_host:file.txt /local/directory/
Copy directory from a remote host to local host:
$ scp -r username@from_host:/remote/directory/ /local/directory/
For AWS Instance with PEM keys
scp -i <pem_key> <source_file> user@host:<location>
scp -i test.pem test.zip ubuntu@XX.XX.XXX.XXX:/ubuntu/home
NOTE: AWS allows only 1 file at a time to copy. You need to ZIP your file and apply command.
SCP Command options
–r Recursively copy entire directories.
-C Compression enable.
-l limit – Limits the used bandwidth, specified in Kbit/s.
-P port – Specifies the port to connect to on the remote host. Note that this option is written with a capital ‘P’.