File Transfer Commands: rsync and scp

Posted on Fri 24 January 2025 in Developer Tools • 2 min read

Two essential tools for moving files between systems: scp for simple copies, rsync for smart synchronization.

scp: Secure Copy

scp copies files over SSH. Simple syntax, works everywhere SSH works.

Basic Examples

Copy file to remote:

scp file.txt user@remote:/path/to/destination/

Copy file from remote:

scp user@remote:/path/to/file.txt ./local/directory/

Copy directory recursively:

scp -r mydir/ user@remote:/path/to/destination/

Copy multiple files:

scp file1.txt file2.txt user@remote:~/

Use non-standard port:

scp -P 2222 file.txt user@remote:/path/

Copy between two remote hosts:

scp user@host1:/path/file.txt user@host2:/path/

When to Use scp

  • One-time file transfers
  • Simple copies where you don't need resume capability
  • When rsync isn't available

rsync: Smart Synchronization

rsync only transfers differences, making it efficient for syncing large directories or resuming interrupted transfers.

Common Options

Flag Description
-a Archive mode (preserves permissions, timestamps, symlinks)
-v Verbose output
-z Compress during transfer
-P Show progress + allow resume
-h Human-readable sizes
-n Dry run (show what would happen)
--delete Delete files in destination not in source

Note: -a is equivalent to -rlptgoD (recursive, links, permissions, times, group, owner, devices).

Basic Examples

Sync local to remote:

rsync -avzP /local/path/ user@remote:/remote/path/

Sync remote to local:

rsync -avzP user@remote:/remote/path/ /local/path/

Trailing slash matters:

# With trailing slash: sync contents of source into destination
rsync -av source/ destination/
# Result: destination/file1, destination/file2

# Without trailing slash: sync source directory into destination
rsync -av source destination/
# Result: destination/source/file1, destination/source/file2

Advanced Examples

Sync with deletion (mirror):

rsync -avzP --delete /local/path/ user@remote:/remote/path/

Dry run first (always recommended for --delete):

rsync -avzPn --delete /local/path/ user@remote:/remote/path/

Ignore permissions (useful for cross-platform):

rsync -avzP --no-perms --no-owner --no-group source/ destination/

Show itemized changes:

rsync -avzPi source/ destination/

The -i flag shows what changed:

  • >f = file transferred
  • .f = file not transferred (identical)
  • c = checksum differs
  • s = size differs
  • t = timestamp differs

When to Use rsync

  • Syncing directories (only transfers changes)
  • Large file transfers (resume on interruption)
  • Backups
  • Any repeated transfer where bandwidth matters

Quick Comparison

Feature scp rsync
Resume interrupted transfers No Yes
Transfer only differences No Yes
Simple syntax Yes More options
Availability Everywhere Usually installed
Delete destination files No Yes (--delete)

Practical Workflows

Backup home directory:

rsync -avzP --delete ~/Documents/ backup-server:~/Documents/

Quick file send:

scp report.pdf colleague@workstation:~/Downloads/

Sync development folder:

rsync -avzP --exclude '.git' --exclude 'node_modules' \
    /local/project/ server:/var/www/project/

For one-off copies, scp is simpler. For anything involving synchronization or large transfers, rsync saves time and bandwidth.