File Transfer Commands
Efficient data movement is a core part of modern system administration and software delivery. Teams move code between local machines and cloud instances, copy logs into archives, synchronize configuration files, and pull reports from remote services. Although the goal is often simple, the tools used to reach it can vary widely.
Why Secure File Transfer Matters
Security is usually the first concern. Commands such as scp, rsync, and sftp can run over SSH, which means the traffic is encrypted. That helps protect data in transit, especially when transferring sensitive files or working across untrusted networks. Speed and convenience matter too, but secure behavior is a strong default.
scp: Quick and Secure Copy
scp is a command-line utility for copying files over a network. It is built on the SSH protocol and is often described as secure copy. Its syntax is close to the standard cp command, which makes it easy to pick up for people familiar with Unix-like systems.
Basic Syntax
- Upload a local file to a remote server:
scp [options] local_file remote_username@remote_host:remote_folder - Download a remote file to a local machine:
scp [options] remote_username@remote_host:remote_file local_folder
Common Options
-r: Recursively copy a directory.-P: Set the SSH port. The letter is uppercase.-p: Preserve modification time, access time, and permissions.
Example
Upload a local archive to a remote server using port 2222:
scp -P 2222 app.tar.gz user@192.168.1.100:/var/www/
Download a remote log file into the current directory:
scp user@192.168.1.100:/var/log/syslog .
rsync: Efficient Synchronization
rsync is a fast and versatile file transfer and synchronization tool. It is especially useful when copying large sets of files or keeping two directories aligned. The command supports incremental transfers, meaning it can send only changed data instead of repeating the full file set.
Basic Syntax
The general form is:
rsync [options] source destination
Common Options
-a: Archive mode, recursive copy with attribute preservation.-v: Verbose output.-z: Compress data during transfer.--progress: Show transfer progress.-e: Specify the remote shell, commonly SSH.
Example
Synchronize a local directory with a remote directory:
rsync -avz --progress website/ user@192.168.1.100:/var/www/html/
The trailing slash has a specific meaning. With a trailing slash, the contents of the source directory are copied. Without it, the source directory itself is copied.
sftp: Interactive File Transfer
Sometimes a task requires browsing a remote file tree before moving something. sftp, or Secure File Transfer Protocol, provides an interactive command-line session. It feels similar to FTP, but the connection is protected.
Basic Usage
Connect to a remote host:
sftp user@192.168.1.100
Once connected, users can run commands such as listing files, changing directories, uploading, and downloading.
lsor