This topic describes how to use file transfer tools, such as SSH File Transfer Protocol (SFTP
), Secure Copy Protocol (SCP
), and Rsync
, to upload files to a Linux Elastic Compute Service (ECS) instance from an on-premises Linux or macOS computer or download files from a Linux ECS instance to an on-premises Linux or macOS computer when the instance is assigned a public IP address.
Tools
Item | SCP | SFTP | Rsync |
Feature | Quickly uploads or downloads a single file or folder. |
| Uses incremental synchronization. Only the content that differs from the content in the destination is transferred to the destination. |
Interaction | Runs commands to perform one-time operations. | Supports interactive commands, similarly to the FTP client. | Runs commands or scripts to perform operations. |
Scenario |
|
|
|
Limits
On-premises operating system | Instance network configuration | File size | Transfer speed | Maximum number of files |
Linux or macOS | The ECS instance is assigned a static public IP address (also called an auto-assigned or system-assigned public IP address) or associated with an elastic IP address (EIP). | Not limited | Not limited | Not limited |
Preparations
Check the status of a Linux ECS instance. The operations described in this topic can be performed on a Linux ECS instance only if the instance is in the Running state.
Obtain the public IP address of the Linux ECS instance. The public IP address of the Linux ECS instance is required to connect to the instance and perform the operations described in this topic.
Check the security groups of the Linux ECS instance. Before you use a tool described in this topic to upload files to the Linux ECS instance, check whether the port used by the tool is open in a security group of the instance. The default port is port 22.
Use SCP to transfer files
SCP is an SSH-based file transfer protocol that provides secure file transfer, copy, and management capabilities. The following section describes how to transfer files by using SCP.
Upload a file or folder
If you want to upload a file or folder from your on-premises computer to the Linux ECS instance, run the following command on your on-premises computer. After you run the command, you may be prompted to enter a password.
# Upload a single file to the Linux ECS instance. scp <File path on your on-premises computer> <Logon username of the Linux ECS instance>@<Public IP address of the Linux ECS instance>:<File path on the Linux ECS instance> # Upload an on-premises folder to the Linux ECS instance. scp -r <Folder path on your on-premises computer> <Logon username of the Linux ECS instance>@<Public IP address of the Linux ECS instance>:<Folder path on the Linux ECS instance>
Download a file or folder
If you want to download a file or folder from the Linux ECS instance to your on-premises computer, run the following command on your on-premises computer. After you run the command, you may be prompted to enter a password.
# Download a single file to your on-premises computer. scp <Logon username of the Linux ECS instance>@<Public IP address of the Linux ECS instance>:<File path on the Linux ECS instance> <File path on your on-premises computer> # Download a folder from the Linux ECS instance to your on-premises computer. scp -r <Logon username of the Linux ECS instance>@<Public IP address of the Linux ECS instance>:<Folder path on the Linux ECS instance> <Folder path on your on-premises computer>
Use SFTP to transfer files
SFTP is an interactive file transfer tool based on the SSH protocol. SFTP supports various features such as file management and resumable file transfer. The following section describes how to transfer files by using SFTP.
Step 1: Connect to the Linux ECS instance
On your on-premises terminal, run the following command to connect to the Linux ECS instance:
sftp <Logon username of the Linux ECS instance>@<Public IP address of the Linux ECS instance>
The following figure shows that you are connected to the Linux ECS instance.
Step 2: Upload or download files
Upload a single file or a folder from your on-premises computer to the Linux ECS instance
# Upload a single file. sftp> put <File path on your on-premises computer> <File path on the Linux ECS instance> # Upload a folder. sftp> put -r <Folder path on your on-premises computer> <Folder path on the Linux ECS instance>
Download a single file or a folder from the Linux ECS instance to your on-premises computer
# Download a single file. sftp> get <File path on the Linux ECS instance> <File path on your on-premises computer> # Download a folder. sftp> get -r <Folder path on the Linux ECS instance> <Folder path on your on-premises computer>
Step 3: Resume the file transfer process when the process is interrupted
If the transfer of a large file is interrupted, replace the get
and put
commands in Step 2 with the reget
and reput
commands to continue the file transfer.
# Resume the upload process.
sftp> reput <Path on your on-premises computer> <Path on the Linux ECS instance>
# Resume the download process.
sftp> reget <Path on the Linux ECS instance> <Path on your on-premises computer>
Step 4: Disconnect from the Linux ECS instance
After the transfer task is completed, run the quit
or bye
command to exit SFTP.
sftp> quit
sftp> bye
Use Rsync to transfer files
Rsync is a file synchronization and transfer tool for Linux and Unix operating systems. You can use Rsync to upload on-premises files to a Linux ECS instance or download files from a Linux ECS instance to your on-premises computer. Rsync also supports the folder synchronization feature. To install and use Rsync, perform the following steps:
Step 1: Install Rsync
Install Rsync on your on-premises computer and the Linux ECS instance. The installation method varies based on the operating system.
Alibaba Cloud Linux 2 and Alibaba Cloud Linux 3
sudo yum install -y rsync
CentOS 6, CentOS 7, and CentOS 8
sudo yum install -y rsync
Ubuntu and Debian
sudo apt install -y rsync
Step 2: Use Rsync to upload or download files
Upload a single file
If you want to upload a file from your on-premises computer to the Linux ECS instance, run the following command on your on-premises computer. After you run the command, you may be prompted to enter a password.
rsync -avz -e ssh <Path of the file or folder on your on-premises computer> <Logon username of the Linux ECS instance>@<Public IP address of the Linux ECS instance>:<Path of the file or folder on the Linux ECS instance>
Download a single file
If you want to download a file from the Linux ECS instance to your on-premises computer, run the following command on your on-premises computer. After you run the command, you may be prompted to enter a password.
rsync -avz -e ssh <Logon username of the Linux ECS instance>@<Public IP address of the Linux ECS instance>:<Path of the file or folder on the Linux ECS instance> <Path of the file or folder on your on-premises computer>
Synchronize (or upload) a folder from your on-premises computer to the Linux ECS instance
If you want to upload (or synchronize) a folder from your on-premises computer to the Linux ECS instance, run the following command on your on-premises computer. After you run the command, you may be prompted to enter a password.
rsync -avz -e ssh <Folder path on your on-premises computer> <Logon username of the Linux ECS instance>@<Public IP address of the Linux ECS instance>:<Folder path on the Linux ECS instance>
Synchronize (or download) a folder from the Linux ECS instance to your on-premises computer
If you want to download (or synchronize) a folder from the Linux ECS instance to your on-premises computer, run the following command on your on-premises computer. After you run the command, you may be prompted to enter a password.
rsync -avz -e ssh <Logon username of the Linux ECS instance>@<Public IP address of the Linux ECS instance>:<Folder path on the Linux ECS instance> <Folder path on your on-premises computer>
References
After you upload files to a Linux ECS instance, you can back up the files. For more information, see Create a snapshot.
The operations described in this topic can be performed to transfer files only between an on-premises Linux or macOS computer and a Linux ECS instance. If your ECS instance runs Windows, you can use other methods to transfer files to the instance. For more information, see Select a file transfer method.
If you want to transfer files from an on-premises Windows computer to a Linux ECS instance, you can use Windows SCP (WinSCP). WinSCP supports SCP and SFTP. For more information, see Use WinSCP to upload a file from an on-premises Windows computer to a Linux instance.
You can use Object Storage Service (OSS) to store and manage files. For more information, see Get started by using the OSS console.