×

Search anything:

Copy files from one server to another server

Internship at OpenGenus

Get this book -> Problems on Array: For Interviews and Competitive Programming

In this article, we have explored the steps to copy files from one remote server to another remote server. This involve using commands like scp or utilities like WinSCP.

Table of contents:

  1. Approach 1: Copy files using SCP command in Linux
  2. Alternative approach using WinSCP

Pre-requisites:

Approach 1: Copy files using SCP command in Linux

The steps to copy files from one server to another server are:

  • Step 1: Get login information for each server.
  • Step 2: Get file path of the files to be copied.
  • Step 3: Login to the second server and use scp command to copy files.

The detailed steps are as follows:

Step 1: Get login information for each server.

Assume we have to copy a file F from server A to server B. Get the Login information for both servers. Be sure to get the IP address of the servers as the hostname will not work with scp command which we will use.

To get the IP address of the system you are logged, use the following command:

ifconfig

It will be as follows:

  • Server A
    • Username: userA
    • Password: pswA
    • IP: aa.bb.cc.dd
  • Server B
    • Username: userB
    • Password: pswB
    • IP: ee.ff.gg.hh

For example, following are information of two servers:

Server A
-----------
IP: 10.103.45.19
Username: opengenus
Password: opengenus=9

Server B
-----------
IP: 10.17.105.22
Username: aditya
Password: aditya=9

Step 2: Get file path of the files to be copied.

Login to remote server using an utility like MobaXterm.

Get the file path of the file you want to copy. If you want to copy an entire directory, get the absolute path of the directory.

We can get the absolute path of the current position we are on using the following command:

pwd

It will give an output as:

/home/opengenus/iq/

It might be that you need to copy the file named "information.txt" in the current location.

Step 3: Login to the second server and use scp command to copy files.

In this step, login to server B where you want to copy the files and go to the location you want to keep the files. Once done, use the following command to copy file named "information.txt" from server A to current server:

scp usernameB@ipB:/absolute_path_to file/ .

Note:

  • . is to get the file in the current working directory. We can specify a path instead it.

For our case, the real command is:

scp opengenus@10.103.45.19:/home/opengenus/iq/information.txt .

To copy the entire directory, use scp -r. The command will be as follows:

scp -r opengenus@10.103.45.19:/home/opengenus/iq/ .

You will be prompted to enter the password of the server A from where files are to be copied. Type the password (will not be visible on screen) and press ENTER key.

With this, you will copy your file or directory successfully.

Alternative approach using WinSCP

In this approach, we need not login to the remote server using a terminal utility. You can browse through the files in a server using an utility like WinSCP.

The approach is as follows:

  • Step 1: Login to server A using WinSCP
  • Step 2: Download the files from server A to your local system (Windows)
  • Step 3: Login to server B using WinSCP
  • Step 4: Upload the local files to server B

To download and upload files, you just need to select the concerned files and drag it to the appropriate location.

With this, you must have a strong idea of how to copy files from one remote server to another remote server.

Copy files from one server to another server
Share this