scp (secure copy) is a popular command line utility, widely used to transfer files from one server to another. The scp command offers the same authentication and services as the ssh commands and transfers files using the ssh protocol. You must have a host account or a key to transfer the files using this command.
In this guide, we will explain how you can quickly copy a file from one server to another using the scp command in Linux.
Copy Files from One Server to Another in Linux Using scp Command
The following is the general syntax of the scp command:
In the above command, the source_file_location is the directory path for a file you want to send. The username is the name of destination host to which you want to send the file. IP_destination_host is the IP address of the destination host, while destination_file_location is the directory path of destination host where the source file is going to be saved.
The scp command can be used with different following options:
-
- -p: it specifies the ssh port of the host.
- -q: this option suppresses the progress.
- -c: this option compresses the data for sending the host machine.
- -r: recursively copy the directories.
Let’s copy the file sample.txt to the directory Documents of the host system [email protected].
Note: Don’t forget to add full path for both source and destination.
When you execute the above command, a question will pop up on your screen, answer with yes to continue the process.
Once the process is finished, go to the destination directory of the system, and you can easily locate the copied file there. In the above example, the sample.txt will be copied to the Documents directory of the system.
Bottom Line
The scp command in Linux securely transfers or copies the directories and files from one server to another. The scp command uses the ssh protocol for data transferring. This article provides a syntax and an example to transfer file from host to remote server.