How to transfer files with scp and rsync in Linux

· Category: Linux

Short answer

scp copies files over SSH; rsync synchronizes directories with delta transfer for efficiency.

Steps

  1. Copy a file with scp:
scp file.txt user@remote:/path/
  1. Copy recursively:
scp -r localdir/ user@remote:/path/
  1. Sync with rsync:
rsync -avz localdir/ user@remote:/path/
  1. Sync with delete:
rsync -avz --delete localdir/ user@remote:/path/

Tips

  • rsync -P shows progress and resumes partial transfers.
  • Use --exclude to skip files during sync.
  • rsync over SSH is the standard for backups and deployments.

Common issues

  • Trailing slashes in rsync paths matter: dir/ copies contents; dir copies the folder.
  • Permission denied: ensure the remote user has write access.