How to Use SCP Command to Transfer Files/Folders in Linux
Table of Contents
- Basic Syntax
- Using SCP Command
Use SCP Command to Transfer Files/Folders in Linux
SCP command is used to copy files between two systems in a secure way. SCP stands for Secure Copy which copies files or directories securely. By using this command you can copy or transfer files from the remote system to the remote system or remote system to the local system. It encrypts data and passwords sent to another system for security. In this tutorial, you are going to learn how to use the SCP command to transfer files/folders in Linux.
Before you start to learn how to use the SCP command to transfer files/folders in Linux. You must have the non-root user account on your system with sudo privileges.
Following is the basic syntax:
scp [OPTION] [[email protected]]SOURCE_HOST:filename1 [[email protected]]DESTINATION_HOST:filename2
-rThis option used for Recursively copying directories.
-Pused for Remote host ssh port.
-CThis option used for compressing data before sending it.
-cThis option used for selecting cipher to transfer data.
Using SCP Command
The following are examples of SCP Command.
1. Provide Estimated Time And Connection Speed
SCP command also provides estimated time and connection speed for transferring the file. You can achieve this by using the
-p option with the SCP command.
scp -p filename.zip [email protected]:.
The output should look like:
[email protected]'s password: Filename.zip 100% 9800KB 178KB/s 00:55
In the following example we will get estimated time to upload the
demo.txt file on the remote server:
2. Use another cipher to encrypt files
By default, SCP uses cipher AES-128 to encrypt files. You can use another cipher using the option
-C with the SCP command.
Following is an example using
scp -C filename.zip [email protected]:.
In the following example, we will upload
demo.txt file with on remote server using
3. Copy files from a local system to the remote system using SCP command.
You can copy files to the remote system from a local system using the following command.
scp filename.zip [email protected]:/path/to/directory
In the above example,
filename.zip will be copied to remote hosts given directory.
Below is another example:
By default it will copy a file to the directory with its default name, If you want to specify a name for the file then you can do so by using the following command.
scp filename.zip [email protected]:/path/to/directory/newfile.zip
In the below example, The file
filename.zip will be copied to remote hosts directory with a
new name as newfile.zip.
One more example:
You can copy directory instead of a file, using the option
-r stands for a recursive copy. In the below example
final_code directory will be copied to remote systems directory.
scp -r /path/to/final_code [email protected]:/path/to/directory
4. Copy a remote file to the local system using SCP command
You can also copy a file from the remote system to the local system in which you should specify the source and destination file name.
In the below example, the file filename.zip on the remote system will be copied to the local systems directory.
scp [email protected]:/path/to/remote/filename.zip /path/to/local/directory
Following is one more example to copy a remote file to the local system:
5. Copy files between two remote systems using
You can copy files between two remote systems using the path to the source and destination directory on each system.
In below example, filename.zip file from the system
139.168.x.x to the specified directory of
scp [email protected]:/files/filename.zip [email protected]:/path/to/directory/
One more example:
You will be also prompted for passwords of both systems for transferring data from one system to another.
If you want to copy directory then you can use the following example command using the option
scp -r [email protected]:/files/ [email protected]:/path/to/directory/
You have successfully learned how to use the SCP command to transfer files/folders in Linux. If you have any queries regarding this then please don’t forget to comment below.
How to Install FFmpeg on Debian 9
How to Install Netbeans on Linux Mint 19
How to Install FFmpeg on Linux Mint 19
How to install Composer on Ubuntu 18.04
How to Install Webmin on CentOS 7
How to Install CMake on Debian 10
How to Install Anaconda on Debian 10
How to Install WordPress with LEMP Stack on Debian 10
How to Install Git on Manjaro 18
How to install Nginx on CentOS 7
How to Install MySQL on Ubuntu 18.04
How to Install PhpStorm on CentOS 8