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 root@8.8.8.8:/path/on/server/to/

Will copy file.txt from your pc to server on IP 8.8.8.8, 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  root@8.8.8.8:/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 root@8.8.8.8:/path/on/server/

WIll copy folder and nested files to /path/on/server/.

⚠ 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 root@8.8.8.8 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.