Search Our Database

Using SCP and rsync for Secure File Transfer

Last updated on |
by

Introduction

Secure file transfer is essential for system administrators, developers, and IT professionals handling sensitive data across networks. Primarily utilized by network administrators, DevOps engineers, and web developers, tools like SCP (Secure Copy Protocol) and rsync rely on SSH to provide encrypted communication. SCP provides simple command-line copying between hosts, whereas rsync offers advanced synchronization features such as resumable transfers and delta-transfer algorithms. They are typically used during deployments, backups, and migrations across Linux, macOS, and Windows environments, helping overcome common challenges like firewall limits and large file timeouts.

 

Prerequisites

  • A local and remote system with SSH access enabled.
  • OpenSSH client version 8.2 or higher installed.
  • rsync version 3.2.3 or higher installed.
  • User account with read/write permissions for the relevant directories.
  • SSH key-based authentication configured (recommended for automation).
  • Basic understanding of the command-line interface.

 

Step-by-step Guide

Step 1: Check SSH Connectivity

Before using SCP or rsync, verify that SSH works between the systems.

ssh username@remote_host

If the connection works and you can log in, proceed with file transfer.

 

Step 2: Transfer Files with SCP or rsync

SCP is ideal for quick, straightforward file or directory copying between local and remote machines.

View SCP Transfer Steps

To copy a single file from a local machine to a remote host:

scp /path/to/localfile.txt username@remote_host:/remote/directory/

To copy a directory recursively:

scp -r /path/to/localdir username@remote_host:/remote/directory/

 

To copy from remote host to local machine:

scp username@remote_host:/remote/file.txt /local/directory/

 

Rsync is preferred for repeated transfers, large files, and backups because it only transfers modified portions of files and supports bandwidth throttling.

View Rsync Synchronization Steps

Before starting the files synchronize, there are some optional criteria for the rysnc command that you might consider:

  • If you are having a particular private key file or using a custom SSH port for the machine:
    rsync -avz -e "ssh -p 2222 -i /path/to/private_key" /local/path username@remote_host:/remote/path

 

  • To avoid saturating the network during large transfers:
    rsync --bwlimit=5000 -avz /local/path username@remote_host:/remote/path

    This example limits bandwidth to approximately 5 MB/s.

 

Basic rsync syntax for local to remote:

rsync -avz /local/path username@remote_host:/remote/path

Explanation of flags:

  • -a: Archive mode (preserves permissions, symlinks, etc.)

  • -v: Verbose output

  • -z: Compress data during transfer

 

To synchronize in the reverse direction, remote to local:

rsync -avz username@remote_host:/remote/path /local/path

 

Conclusion

SCP provides a straightforward way to securely transfer files over SSH, while rsync offers more advanced synchronization features, bandwidth control, and incremental updates. For one-time simple copies, SCP is sufficient; for ongoing synchronization or large datasets, rsync is more efficient. Mastering both tools enables secure, optimized, and automated file transfers in a variety of scenarios.

 

Should you have any inquiries about the guidelines, please feel free to open a ticket through your portal account or contact us at support@ipserverone.com. We’ll be happy to assist you further.