File transferring with SCP and Rclone
Learn how to efficiently transfer files to and from your cloud instances.
Introduction
Transferring files to and from your cloud instances is a common task when working with cloud computing. In this guide, we'll cover two powerful methods for file transfers:
- SCP (Secure Copy Protocol): A simple, built-in utility that comes with SSH for transferring individual files or directories
- Rclone: A more advanced tool that supports many cloud storage providers and offers more features for synchronizing directories
Using SCP
SCP (Secure Copy Protocol) is a command-line utility that allows you to securely transfer files between computers using SSH encryption.
Prerequisites
- SSH access to your instance (see How to SSH into your instance)
- The public IP address of your instance
- Username and SSH key or password for your instance
Basic SCP Usage
Copying a file from your local machine to the instance
scp /path/to/local/file username@instance_ip:/path/on/instanceExample:
scp data.csv ubuntu@192.168.1.100:/home/ubuntu/data/Copying a file from the instance to your local machine
scp username@instance_ip:/path/on/instance /path/to/local/destinationExample:
scp ubuntu@192.168.1.100:/home/ubuntu/results.csv ./downloads/Copying an entire directory recursively
scp -r /path/to/local/directory username@instance_ip:/path/on/instanceExample:
scp -r ./project ubuntu@192.168.1.100:/home/ubuntu/Advanced SCP Options
-P port: Specify a custom SSH port (e.g.,scp -P 2222 file.txt user@host:/path)-i identity_file: Specify an SSH private key file (e.g.,scp -i ~/.ssh/my_key file.txt user@host:/path)-C: Enable compression for faster transfers over slow connections-l limit: Limit bandwidth in Kbit/s
Using Rclone
Rclone is a command-line program to sync files and directories between cloud storage services and your local machine. It's more powerful than SCP and supports many cloud providers.
Installing Rclone
On Linux
curl https://rclone.org/install.sh | sudo bashOn macOS (with Homebrew)
brew install rcloneOn Windows
Download the Windows installer from rclone.org/downloads
Configuring Rclone for SFTP
To transfer files to your instance using SFTP via Rclone:
- Run
rclone configto create a new remote - Choose a name for your remote (e.g., "my-instance")
- Select "sftp" as the storage type
- Enter your instance's IP address as the host
- Enter your username
- Choose your authentication method (key file or password)
- Save the configuration
Basic Rclone Usage
Copying files to your instance
rclone copy /local/path remote-name:/remote/pathExample:
rclone copy ./data my-instance:/home/ubuntu/dataCopying files from your instance
rclone copy remote-name:/remote/path /local/pathExample:
rclone copy my-instance:/home/ubuntu/results ./downloadsSynchronizing directories
rclone sync /local/path remote-name:/remote/pathExample (this will make the remote directory identical to the local one):
rclone sync ./project my-instance:/home/ubuntu/projectWarning: The sync command will delete files at the destination that aren't in the source. Use with caution!
File Transfer Best Practices
- Compress large files or directories before transferring to save bandwidth and time
- Use bandwidth limiting when transferring large amounts of data to avoid network saturation
- For repeated transfers, consider setting up SSH keys to avoid typing passwords
- When transferring sensitive data, ensure your connection is secure (both SCP and Rclone with SFTP use SSH encryption)
- For very large datasets, consider using object storage solutions like AWS S3 or Google Cloud Storage
- Schedule large transfers during off-peak hours to minimize impact on other users
Last updated 8 months ago
Was this helpful?