Secure File Transfers
Secure file transfers are an essential aspect of remote administration. SSH offers two main options for securely transferring files: scp
and sftp
. Additionally, alternatives such as rsync
and rclone
provide more advanced functionality for specialized use cases.
Transferring Files via SSH (scp, sftp)
Using scp
scp
(secure copy) is a command-line utility that uses SSH to securely transfer files between local and remote systems.
Example:
scp file.txt user@remote-host:/path/to/destination/
This command copies file.txt
from the local machine to the specified path on the remote host. To copy files from the remote machine to the local machine:
scp user@remote-host:/path/to/file.txt /local/destination/
scp
is often chosen for quick, simple transfers, though it is less efficient than other tools when copying large data sets or synchronizing directories.
Using sftp
sftp
(SSH File Transfer Protocol) provides an interactive interface for securely transferring files over SSH. It allows navigation of the remote filesystem and the transfer of files in an interactive manner.
Example:
sftp user@remote-host
Within the sftp
session:
put file.txt
uploads a file to the remote system.get file.txt
downloads a file from the remote system.ls
lists files in the remote directory.
sftp
offers more control over file transfers and is ideal for managing files interactively.
Alternatives to scp: rsync and rclone
While scp
and sftp
are widely used, tools like rsync
and rclone
offer advanced features for specific scenarios.
Using rsync
with SSH
rsync
enables efficient file transfers over SSH, synchronizing files and directories between systems while transferring only the changes. This makes it ideal for backups and large directory synchronizations.
Example (with SSH):
rsync -avz -e ssh file.txt user@remote-host:/path/to/destination/
-e ssh
: Specifies SSH as the transfer method.-avz
: Enables archive mode (preserving permissions), verbosity, and compression.
This command securely transfers file.txt
to the remote system, with rsync
ensuring that only changes are transmitted.
Using rclone
with SSH
rclone
supports file transfers over SSH using the sftp
protocol, along with its extensive support for cloud storage providers. It is well-suited for managing files across multiple environments, including cloud storage and remote systems.
Example (with SSH):
rclone copy file.txt :sftp:user@remote-host:/path/to/destination/
In this example, :sftp:
ensures that the sftp
protocol is used over SSH for secure transfers.
This page outlines secure file transfer methods using SSH and presents alternatives that offer more advanced features. For complex transfers or regular backups, tools like rsync
and rclone
provide greater flexibility and efficiency.