How can I copy a folder from one Ubuntu server to another Ubuntu server?
- User
How can I copy a folder from one Ubuntu server to another Ubuntu server?
Assistant
To copy a folder from one Ubuntu server to another, you can use several methods depending on your needs and environment. Here are the most common and effective ways:
✅ 1. Using
rsyncover SSH (Recommended)rsyncis fast, efficient, and supports resuming interrupted transfers.Syntax:
rsync -avz -e ssh /path/to/local/folder username@remote_server:/path/to/remote/destinationExample:
rsync -avz -e ssh /var/www/html user@192.168.1.10:/backup/Explanation:
-a: Archive mode (preserves permissions, timestamps, etc.)-v: Verbose output-z: Compress during transfer-e ssh: Use SSH for secure transfer
✅ 2. Using
scp(Secure Copy)Good for simple transfers without advanced features like resume support.
Syntax:
scp -r /path/to/local/folder username@remote_server:/path/to/remote/destinationExample:
scp -r /home/user/myproject user@192.168.1.10:/home/user/-r: Copy recursively (required for folders)
✅ 3. Using
tarover SSH (for large directories)This method packs the directory on the source machine and unpacks it on the destination.
From the destination server:
ssh user@source_server "tar cvzf - /path/to/source/folder" | tar xvzf -Example:
ssh user@192.168.1.5 "tar cvzf - /var/log" | tar xvzf -- This streams the folder compressed through SSH to the current directory.
✅ 4. Mount remote directory with
sshfsand copy locallyIf you prefer working with local tools:
Install sshfs:
sudo apt install sshfsMount remote folder:
sshfs user@remote_server:/remote/path /mnt/local_mount_pointThen copy using
cpor file manager:cp -r /mnt/local_mount_point/folder /local/destination/
✅ 5. Using Network File Sharing (NFS or Samba)
If both servers are on the same network, you can set up NFS or Samba share and directly access the remote folder as if it's local.
- More complex to set up but useful for frequent transfers.
🛡️ Tips:
- Make sure SSH is installed and running on both servers.
- If copying large files or directories,
rsyncis preferred because it can be resumed and is more efficient. - Always test with a small folder first.
- For automation, consider setting up SSH key-based authentication.
Let me know if you want help automating this or setting up SSH keys!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.