Table of Contents
- Basic Syntax For SCP Command
- Using SCP Command
Use SCP Command to Transfer Files/Folders in Linux
SCP command is used to copy files between to systems in a secure way. SCP stands for Secure Copy which copies files or directories securely. By using SCP command you can copy or transfer files from the remote system to the remote system or remote system to the local system. SCP command encrypts data and passwords sent to another system for security. In this tutorial, you are going to learn how to use SCP command to transfer files/folders in Linux.
Before you start to learn how to use SCP command to transfer files/folders in Linux. You must have the non-root user account on your system with sudo privileges.
Basic Syntax For SCP Command
Following is the basic syntax for SCP command.
scp [OPTION] [[email protected]]SOURCE_HOST:filename1 [[email protected]]DESTINATION_HOST:filename2
-roption used for Recursively coping directories.
-Pused for Remote host ssh port.
-Coption used for compressing data before sending.
-coption used for selecting cipher to transfer data.
Using SCP Command
Following are the examples for SCP Command.
1. Provide Estimated Time And Connection Speed
SCP command also provides estimated time and connection speed for transferring file. You can achieve this by using
-p option with 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 following example we will get estimated time to upload
demo.txt file on 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 SCP command.
Following is an example using
scp -C filename.zip [email protected]:.
In 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 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 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 option
-r stands for a recursive copy. In 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 local system using SCP command
You can also copy a file from the remote system to the local system using SCP command in which you should specify the source and destination file name.
In below example, the file filename.zip on remote system will be copied to 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 local system using SCP command:
5. Copy files between two remote systems using SCP command
You can copy files between two remote systems using the path to source and destination directory on each system.
In below example, filename.zip file from 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 option
scp -r [email protected]:/files/ [email protected]:/path/to/directory/
You have successfully learned how to use SCP command to transfer files/folders in Linux. If you have any queries regarding this then please don’t forget to comment below.