← Back to articles

How to Transfer Files over SSH: scp, rsync, sftp

6 Jul 2025 • Linux, SSH • 6 min read

Objective: You have two Linux machines (or a local computer and a remote server), and you want to transfer files between them over the network, securely. We'll see three classic tools: scp, rsync, and sftp.


Why transfer files over SSH?

SSH (Secure Shell) is not just for remote terminal access. It can also be used to transfer files securely. Unlike FTP or HTTP, all data is encrypted end-to-end.

You'll most often use these methods to:

  • Transfer configuration files or scripts to a remote server
  • Back up folders from a server to your computer
  • Copy a file from one machine to another (via command line)
  • Synchronize a folder between two machines (e.g., for automation)

Common requirement: SSH access

For all the methods below, you need:

  • A user with SSH access to the server
  • A public/private SSH key pair set up (optional but highly recommended)

Example connection:

ssh user@server_ip

1. scp — Quick and simple

scp (secure copy) is the easiest tool. It allows copying a file or folder between two systems via SSH.

Syntax:

scp SOURCE DESTINATION

Examples:

Send a file to a remote server:

scp myfile.txt admin@192.168.1.10:/home/admin/

Retrieve a file from the server:

scp admin@192.168.1.10:/etc/nginx/nginx.conf .

Copy an entire folder:

scp -r myfolder/ admin@192.168.1.10:/home/admin/

Pros: Simple, available by default on most systems

Cons: No resume support, not efficient for large transfers


2. rsync — Efficient and powerful

rsync is ideal for syncing files and folders. It only sends changes, making it very efficient.

Syntax:

rsync [options] SOURCE DESTINATION

Examples:

Send a folder to the server:

rsync -avz myfolder/ admin@192.168.1.10:/home/admin/myfolder/

Retrieve a folder from the server:

rsync -avz admin@192.168.1.10:/etc/nginx/ ./nginx_backup/

Pros: Fast, resumable, intelligent

Cons: Needs to be installed (not always by default on minimal servers)


3. sftp — Interactive and familiar

sftp is an interactive tool similar to FTP, but secured with SSH.

Connect to a server:

sftp admin@192.168.1.10

You'll enter an SFTP session:

sftp>

Commands to know:

  • ls – list files
  • cd – change remote directory
  • lcd – change local directory
  • get file – download a file
  • put file – send a file

Example:

sftp> put myfile.txt
sftp> get remote_file.txt

Summary table

Tool Use case Pros Cons
scp One-time transfer Simple, fast to use No resume, sends all
rsync Synchronization, backups Fast, resumable, efficient Needs installation
sftp Interactive transfers Familiar commands Not ideal for automation

Conclusion

Now you know how to transfer files securely using SSH!

  • Use scp for quick and occasional transfers
  • Use rsync for regular syncing and backups
  • Use sftp if you prefer a manual interface