Open In App

How to Download a File from a Server with SSH / SCP?

Last Updated : 05 Feb, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Secure Copy Protocol (SCP) is a secure file transfer protocol that allows you to transfer files between computers over a secure connection. It is based on the Secure Shell (SSH) protocol and is commonly used to transfer files between servers and local computers. One of the main benefits of using SCP is that it encrypts the data being transferred, ensuring that it is secure and cannot be intercepted by third parties. This is particularly important when transferring sensitive data, such as passwords or financial information.

To use SCP, you will need to have an SSH client installed on your local machine. If you are using a Unix-based operating system, such as Linux or macOS, you should already have an SSH client installed. If you are using Windows, you can use an SSH client like PuTTY.

The basic syntax for using SCP to transfer a file is as follows:

Syntax:

scp source destinationor

The source is the file you wish to transfer and the destination is the location where you want to save the downloaded file

Pre-requisite:

Make sure the local machine has SSH client installed to be able to use the SCP command.

Downloading a File from a Server with SSH/ SCP

For demonstration purposes, a file named sample.txt is created on the server with the content:

cat sample.txt

 

Step 1: Open a new terminal in Linux/UNIX or command prompt in Windows.

Step 2: Enter the following command to download the file

scp username@<public ip>:/<path to source file> /<path to destination>

This command will fetch the file using the path from the server’s public IP mentioned and download it to the specified destination.

scp -r root@13.10.19.174:/home/harsh/sample.txt /Downloads/sample.txt

 

 

The file has been downloaded from the source; sample.txt.

 

The file is downloaded successfully.

Downloading a complete directory from Server

Directory in the server:

 

Step 1: Open a new terminal in Linux/UNIX or command prompt in Windows.

Step 2: To download a complete directory using the -r switch along with SCP command.

scp -r username@<public ip>:/<path to source file> /<path to destination>

This command will download the entire folder to the specified location using the path from the server’s public IP address.

scp -r root@13.40.79.168:/home/harsh/sample_directory sample _directory

 

 

The folder is downloaded successfully.

 

Below we have opened the sample1.txt file which was in sample_directory. 

 

Below we have opened the sample2.txt file which was in sample_directory. 

 

The complete Folder is downloaded successfully.

Conclusion

SCP, or secure file transfer protocol, enables the transfer of files between computers using a secure connection. It is perfect for sharing sensitive information because it uses SSH to encrypt the data being shared. You must have an SSH client set up on your local machine in order to utilize SCP. SCP’s default file transfer syntax is scp source destination, and you can download entire directories by using the -r flag. It’s vital to remember that in order to use the SCP command, you must have an SSH client installed on your local computer.



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads