How to write an SCP command in terminal
SCP is a command from SSH toolset used to copy files from one host to another. Oftenly it is used to copy files from your local PC to the server on which you have SSH access, or reversely from the server to your local PC.
How to write a command:
scp /path/to/file.txt firstname.lastname@example.org:/path/on/server/to/
file.txt from your pc to server on IP
220.127.116.11, by accessing ssh for the root user. You should know the password of the root user or have your public key installed to
/root/.ssh/authorized_keys on server.
Reverse operation - copy from server to local pc:
scp email@example.com:/path/on/server/to/file.txt /path/on/local/machine/
How to write SCP command to copy the folder📂
To copy folder between hosts:
scp -r /path/to/folder firstname.lastname@example.org:/path/on/server/
folder and nested files to
⚠ If your folder has a lot of small files inside we strongly recommend not use SCP, but use
tar + ssh command to speed the process up:
tar -czf - /path/to/folder | ssh email@example.com tar -xzf - -C /path/on/server/
It is the faster equivalent for the above command. Why: because how long does a server transfer take depends not on size, but on files count. Here we just tar files with simple GZIP compression to one stream and pass this stream over SSH stdio.