Copy Folder from Remote to Local in Ubuntu Linux using scp, rsync, SFTP

Copy Folder from Remote to Local in Ubuntu Linux using scp, rsync, SFTP

Sometimes you need to take a backup of the directory/folder or file from the remote server to the local server. When you have to copy directories/folders or files from the remote server to the local server. For this, in this tutorial, you will learn simple 3 methods using which you can copy remote server directory/folder or files to the local machine in Linux ubuntu.

How to Copy Folder from Remote to Local in Linux Ubuntu using scp, rsync, SFTP

Using the following methods, you can copy folders/directories from the remote server to the local in Linux ubuntu:

  • Method 1: Using SCP (Secure Copy)
  • Method 2: Using Rsync
  • Method 3: Using SFTP (Secure File Transfer Protocol)

Method 1: Using SCP (Secure Copy)

Firstly, open your terminal and execute the SCP linux command to copy a folder from a remote server to a local machine using SCP:

scp -r username@remote:/path/to/folder /path/to/local/folder

Here’s a breakdown of the scp command and its arguments:

  • scp: This is the command used to copy files and directories between two systems securely.
  • -r: This option enables the recursive mode, which copies directories and their contents recursively.
  • username: This is the username of the user account on the remote system.
  • @: This symbol separates the username and the hostname of the remote system.
  • remote: This is the hostname or IP address of the remote system.
  • :/path/to/folder: This is the absolute path to the folder on the remote system that you want to copy.
  • /path/to/local/folder: This is the absolute path to the local folder where you want to copy the remote folder.

Method 2: Using Rsync

In this method, firstly, connect to the remote server by executing the following command on terminal or command line:

ssh [email protected]

Note that, please replace the following in the above command

  • remoteuser” with the username of the remote server
  • remote.server.com” with the IP address or hostname of the remote server

Once you have connected to the remote server using the above-given command. After that, execute the following command on the terminal to navigate to the folder that you want to copy:

cd remote_folder_path

Note that:- Replace “remote_folder_path” with the path to the folder you want to copy.

Execute the following command on terminal to copy a folder from a remote server to a local machine using Rsync:

rsync -avz -e ssh username@remote:/path/to/folder /path/to/local/folder

Here’s a breakdown of the rsync command:

  • rsync: The command to start the rsync process.
  • -avz: The flags used to specify the options for the transfer:
    • -a: The archive flag. This flag is used to preserve the permissions, ownership, timestamps, and other attributes of the files being transferred. It is equivalent to using the options -rlptgoD.
    • -v: The verbose flag. This flag is used to show the progress and details of the transfer in the terminal.
    • -z: The compression flag. This flag is used to compress the data during transfer, which can help to reduce the amount of data being transferred over the network.
  • -e ssh: The flag used to specify the remote shell to use for the transfer. In this case, ssh is used as the remote shell to securely transfer data over the network.
  • username@remote:/path/to/folder: The source of the transfer. This specifies the username, remote host, and path to the folder on the remote host from which the files will be transferred.
  • /path/to/local/folder: The destination of the transfer. This specifies the path to the local folder where the files will be transferred.

Method 3: Using SFTP (Secure File Transfer Protocol)

In this method, you can also copy or transfer directories or files from remote server to local.

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

sftp username@remote

After this, a prompt will open, in which you will have to enter the password to connect to your server.

Once you are connected to the remote server, execute the following command at a terminal or command prompt to navigate to the directories or folders that you want to copy:

cd directory_name

Execute the get following command on terminal or command line to copy the folder to the local machine

get -r foldername /path/to/local/folder

Here’s a breakdown of the get command:

  • get: This is the command used in SFTP to retrieve files or directories from the remote server and copy them to the local machine.
  • -r: This is an option or flag used with the get command to recursively copy the contents of a directory along with its subdirectories and files.
  • foldername: This is the name of the folder that you want to copy from the remote server to the local machine.
  • /path/to/local/folder: This is the destination path on the local machine where you want to copy the folder. The folder will be copied to the specified location along with its contents.

Conclusion

That’s it. In this tutorial, you have learned three popular methods: SCP, Rsync, and SFTP, that can copy your folders/directories or files from a remote server to local. Each method has its advantages and disadvantages, so choose the one that best suits your needs.

Recommended Tutorials

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of 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 from a starting stage. As well as demo example.

Leave a Reply

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