Objective of this article:
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 in the following cases:

  • 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 like this:

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

βœ… Pros: Familiar for FTP users, allows browsing
❌ Cons: Less scriptable, slower for large files


πŸ“Š 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! Whether you’re copying a simple config file or syncing entire directories, there’s a tool for you.

  • 🟒 Use scp for quick and occasional transfers
  • πŸ” Use rsync for regular syncing and backups
  • πŸ“‚ Use sftp if you prefer a manual interface

Feel free to test these tools on a local network before using them in production!