📁 Transferring Files Between Systems
Securely moving files between local and remote systems is a fundamental skill when working with SSH. The two primary tools for this are scp (Secure Copy) for direct file transfers and sftp (SSH File Transfer Protocol) for interactive file management sessions.
Using scp (Secure Copy)
scp (Secure Copy) lets you copy files to or from a remote system over SSH. It's straightforward for single file or directory transfers.
This command copies a local file to a remote system.
This command copies a file from a remote system to your current local directory (the dot represents the current directory).
This command copies an entire directory recursively to the remote system. The -r flag is essential for copying directories.
Using sftp (Interactive Transfer)
sftp opens an interactive session like an FTP client, but encrypted. It's useful for multiple file operations in one session.
This command starts an SFTP session. Once connected, you can use various commands:
- ls → list files on the remote system
- cd folder → change directory on the remote system
- get file.txt → download a file from remote to local
- put file.txt → upload a file from local to remote
- exit → close the SFTP session
Practical Examples
Here are some common real-world scenarios:
Example 1: Backing up a log file from a remote server to your local backup directory.
Example 2: Uploading website files to a remote web server directory.
sftp> cd /var/www/html sftp> put index.html sftp> exit
Example 3: Interactive file management with SFTP, changing directory on the remote system and uploading a specific file.
Real-life analogy
Imagine sending a secure package through a courier that can't be opened by anyone else — that's scp. Think of sftp as walking through the remote system with a secure flashlight, picking up or dropping off files wherever you need. With scp and sftp, you can easily transfer files or folders between computers without worrying about security.