Transfering files between a remote server to a local machine

As a site administrator we often need to upload/download different files. There are different methods you can use to accomplish this and the most well known way is to use FTP. While this is effective but it is not always the quickest way possible.

Instead of all this, you can use different Linux commands to perform your tasks. In this tutorial, I am going to show few examples that will definitely ease your daily routines and it will also help you to learn something new.

Copying files over SSH

Copying files over SSH is a good and proper secured way for moving files between two machines. For that purpose, you can use command such as scp. Scp stands for “secure copy” and it takes different arguments that can help you copy files from remote machine. Assuming that the SSH port for the remote server is 22, you can use the following syntax to copy files over SSH:

scp user@remote-server:/path/to-your/file /local/path/for/file

Example:

scp [email protected]:/home/cppl/work.txt /home2/cppl/content/

The file work.txt is located on server with IP address 192.168.17.133 in directory:

/home/ccpl/work.txt

I will copy it on my local machine in:

/home2/cppl/content/work.txt

When we are copying the files , we don’t need to specify the full path. For example you can go to the destination where we wish to copy the file and use . (dot) to copy the file in the current directory. Here is the example:

cd /home2/cppl/content/
scp [email protected]:/home/cppl/work.txt .

Some servers don’t use port 22 for SSH. You can use the scp command with port no also.

If you want to copy a whole directory, Here you can use -r argument. This argument specifies that the files should be copied recursively. In the below example we will copy the whole folder and all of it’s contents:

scp -P4567 -r [email protected]:/home/cppl/content ~

That’s all, Now you know how to securely copy files between different computers. As you can see SCP is a pretty convenient tool to copy files from one server to another. easily. 

You also like to know SSH Key Generation For Passwordless SSH Login In LinuxPlease check my previous article on this and also give your opinion below if you experience any issues or to discuss your ideas and experiences.