How to Copy Directory from One Remote Server to Another in Linux

1. Log in to the source server using SSH.

2. Create a tar archive of the directory you want to copy.

3. Transfer the tar archive to the destination server using SCP.

4. Log in to the destination server using SSH.

5. Extract the tar archive to the desired location.
[ad_1]

If you want to copy directories and folders from one remote server to another remote server. So for this, you have two different commands scp and rsync of Linux. With the help of this, you can do this.

In this tutorial, you will learn how to copy a directory or folder from one remote server to another remote server in Linux using scp and rsync commands.

How to Copy Directory from One Remote Server to Another in Linux

You can copy directories and folders from one remote server to another remote server by using the following these two methods:

  • Method 1: SCP command in Linux to copy a directory or folder from one remote server to another

  • Method 2: Copy folder or directory from one remote server to another in Linux using rsync

Method 1: SCP command in Linux to copy a directory or folder from one remote server to another

Using the SCP command in Linux, you can copy a directory or folder from one remote server to another:

  • Step 1: Connect to Source Server using SSH
  • Step 2: Copy the Directory From One server to Another using SCP
  • Step 3: Verify the directory copy

Step 1: Connect to Source Server using SSH

Firstly, open your terminal or command line and execute the following command into it to connect source server using ssh command:

ssh [email protected]_server_ip

In this command, you need to replace username with your remote server username and source_server_ip with your server ip address.

Step 2: Copy the Directory From One server to Another using SCP

Once you have connected to the source server, then execute the following command on the terminal or command line to copy the directory from the source server to the destination remote server:

scp -r /path/to/source/directory [email protected]_server_ip:/path/to/destination/directory

In this command, you need to replace the followings:

  • the username with your destination remote server username and source_server_ip with your destination remote server ip address.
  • /path/to/source/directory with the path to the directory you want to copy on the source server, and /path/to/destination/directory with the path to the directory you want to copy the directory to on the destination server Want to.

Note:- If this is the first time you are connecting to the destination server, you will be prompted to enter the password for the destination server. Enter the password to complete the copy.

Step 3: Verify the directory copy

After the copy is complete, you can verify that the directory was copied successfully by logging into the destination server and navigating to the directory where you copied the files.

Method 2: Copy folder or directory from one remote server to another in Linux using rsync

  • Step 1: Connect to Source Server using SSH
  • Step 2: Copy the Directory From One server to Another using rsync
  • Step 3: Verify the directory copy

Step 1: Connect to Source Server using SSH

Firstly, open your terminal or command line and execute the following command into it to connect source server using ssh command:

ssh [email protected]_server_ip

In this command, you need to replace username with your server username and source_server_ip with your server ip address.

Step 2: Copy the Directory From One server to Another using rsync

Execute the following rsync command on terminal to copy the directory or folder from the source server to the destination server

rsync -avzhe ssh /path/to/source/directory [email protected]:/path/to/destination/directory

In this command, you need to replace the followings:

  • the username with your destination remote server username and source_server_ip with your destination remote server ip address.
  • /path/to/source/directory with the path to the directory you want to copy on the source server, and /path/to/destination/directory with the path to the directory you want to copy the directory to on the destination server Want to.

Step 3: Verify the directory copy

After the copy is complete, you can verify that the directory was copied successfully by logging into the destination server or another remote server and navigating to the directory where you copied the directories or folders.

Conclusion

Using rsync and scp linux command, to copy a directory from one remote server to another remote server in Linux is a powerful and efficient way to transfer directories or folders and files. By following the steps outlined in this method, you can easily copy a directory from one remote server to another remote server in Linux using rsync and scp.

Recommended Tutorials

[ad_2]

Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

GSTIN is 03EGRPS4248R1ZD.

Contact
Jassweb, Rai Chak, Punjab, India. 143518
Item added to cart.
0 items - 0.00