Why use rsync for file transfers?
Unlike basic SCP (Secure Copy), rsync provides:
- Faster Transfers – Only transfers differences between files, reducing data usage.
- Resumable Transfers – If interrupted, rsync can continue from where it left off.
- Preservation of File Attributes – Keeps permissions, timestamps, symbolic links, etc.
- Downloading Files from a Server to Local Machine
- Run the following command in your local machine’s terminal (not on the remote server):
1rsync -avz serverXXX@serverXXX.host.com:directory/data ~/Downloads/
What this command does:
Connects to the remote server (serverXXX.host.com§). Downloads the directory/data from the remote server to ~/Downloads/ on your local machine. Maintains file attributes and compresses data for efficiency. Uploading Files from Local Machine to Remote Server To send a file or folder to a remote server, use:
1rsync -avz ~/Downloads/new-os server2X@server2X.host.com:second-directory
What this command does:
Transfers the directory directory from ~/Downloads/ on your local machine. Uploads it to the shb directory on the remote server (server2X.host.com). Ensures efficient and secure transfer using SSH.
Explanation of rsync options
Option Description
-a Archive mode (preserves permissions, timestamps, symbolic links, etc.) -v Verbose mode (displays progress) -z Compresses data during transfer for better performance
Additional useful rsync flags
--progress → Shows real-time progress of the transfer. --delete → Deletes files on the destination if they no longer exist on the source. -e "ssh -p PORT" → If your SSH server runs on a non-default port, specify it.
Conclusion
Using rsync over SSH is an efficient way to transfer files between your local machine and a remote server. It’s faster, more reliable, and preserves file attributes, making it a better alternative to scp.
Comments
You must be logged in to comment.
Loading comments...