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

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 username@source_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 username@destination_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 username@source_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 username@destination-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.

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

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *