How to use scp command to transfer data between two Linux servers

When we manage the server or VPS, we often upload and download data. For example, when we need to move data from one server to another, we usually download the data from the first server to our computer, and then upload the downloaded data to the remote server through the ftp tool. But this is a waste of time and energy. Why don’t we pack it on the first server and transfer the data directly to another server? The scp command in Linux just happens to be able to transfer data between the two servers.

What is scp

scp is a secure copy, which is used for remote file copy. Data transmission uses ssh, and uses the same authentication method as ssh, providing the same security guarantee. Unlike rcp, scp will ask you for a password or passphrase when authentication is required.

Use

Example

Copy from local to remote

scp /home/backup.zip root@www.example.com:/home/others/backup //send the local file backup.zip to the remote backup directory
scp /home/backup.zip root@www.example.com:/home/others/otherbackup.zip //the local file backup.zip sent to the remote otherbackup.zip file.

scp -r /home/backup root@www.example.com:/home/others/ //Copy the local directory backup to the remote directory others

Copy from remote to local
scp root@www.example.com:/home/others/bakcup.zip /home/newbackup.zip //download the remote file backup.zip to the local file newbackup.zip
scp -r root@www.example.com:/home/backup /home/other/ //download the remote directory backup to the local directory other