Introduction
SCP (Secure Copy Protocol) allows you to copy files and directories between two remote systems or between a local machine and a remote machine. The SCP command uses SSH
for data transfer.
In this article, we will discuss the SCP command which is used for file transfer with the help of an example
SCP uses SSH (Secure Shell) for file transfers to ensure the authenticity, encryption, and confidentiality of the data. Thus, there is no chance of snooping on the data in transit. This protocol allows clients to upload and download files and directories to and from a server. The default port for SCP is TCP port 22
SCP Command Syntax
Thescp
command syntax takes the following form:
scp [Parameter] [user@][remote server 1 url or ip address:]path_of_sourcefile [user@][remote server 2 url or ip address:]path_of_destinationfile
[Parameter]
- specifies the parameter that can be given to the SCP command.- Here are some of the details about SCP parameters:
Parameter
Description
-r To recursively copy directories. -q Any information other than errors and the progress meter will be hidden. -C Used when sending data to its destination, it is compressed. -P Specifies the destination SSH port. -p Preserves file access times.
- Here are some of the details about SCP parameters:
[user@]remote server 1 url or ip address:]path_of_sourcefile
[user@]remote server 2 url or ip address:]path_of_destinationfile
For example:
scp root@idrivecompute1.com:/files/file.txt root@idrivecompute2.com:/files/file.txt
Copy a File Between Two Remote Systems using thescp
Command
The following command will copy the file/files/file.txt
from the remote server idrivecompute1.com
to the directory/files
on the remote server idrivecompute2.com
.
scp user1@idrivecompute1.com/files/file.txt user2@idrivecompute2.com:/files
You will be prompted to enter the passwords for both remote accounts. After successful authentication, the data will be transferred directly from one remote system to the other.
If the server is SSH authenticated then the following command will copy the file to the destination location
Note: SSH public keys of both remote servers should be present in respective paths.
scp /files/file2.txt root@idrivecompute2.com:/files/file2.txt
- With the "-3" option, traffic can be routed through the machine executing the command:
scp -3 user1@idrivecompute1.com:/files/file.txt user2@idrivecompute2.com:/files