All Products
Search
Document Center

Elastic Compute Service:Use SFTP or SCP to upload files from or download files to a local computer that runs a Linux or macOS operating system

Last Updated:Mar 06, 2024

If your local computer runs a Linux or macOS operating system, you can use SFTP or SCP to upload local files to a Linux instance or download files from an Linux instance to your local computer.

What are SFTP and SCP? What are the differences between them?

SSH File Transfer Protocol (SFTP) and Secure Copy (SCP) are both network protocols for securely transferring files over the SSH protocol. The following table describes the main differences between SFTP and SCP:

Item

SFTP

SCP

Transmission speed

Slower than SCP

Faster than SFTP

Resumable upload

Supported

Not supported

How to use

Graphical interface and command line

Command line

Other features

Actions such as deleting or renaming files are supported

No other features are supported.

Scenario

Prerequisite

  • The ECS instance is in the Running state.

  • The external public IP address of the ECS instance is obtained.

    Note

    If your ECS instance cannot communicate with the Internet, you can associate the instance with an elastic IP address (EIP). For more information, see Associate or disassociate an EIP.

  • Port 22 is open in the inbound rule of the security group to which the instance belongs. For more information, see Add security group rules.

Run SFTP commands to upload or download files

  1. Remotely connect the instance on the terminal.

    sftp [The logon username]@[The public IP address of the instance]
  2. Upload or download a file or a folder.

    # Upload a file to the instance.
    put -r [The absolute path of the file or folder in the local computer] [The root directory that stores the file in the ECS instance]
    # Download the file to your local computer.
    get [The absolute path of the file or folder in the ECS instance] [The root directory that stores the file in the local computer]

    Example: Run the following command to upload /users/file.txt in the local computer to the /home/ecs-user directory in the ECS instance:

    put -r /users/file.txt /home/ecs-user

Run SCP commands to upload or download files

Upload local files to an ECS instance

scp [The absolute path of the local file] [The logon username]@[The public IP address of the instance]:[The root directory that stores the file in the instance]

Example:

Run the following command to upload /home/test001.txt in the local computer to the /home directory of the ECS instance whose public IP address is 121.40.XX.XX:

scp /home/test001.txt root@121.40.XX.XX:/home

Download a file to a local computer

scp [The logon username]@[The public IP address of the instance]:[The absolute path of the file in the ECS instance] [The root directory that stores the file in the local computer]

Example:

Run the following command to download the /home/test001.txt in the ECS instance whose public IP address is 121.43.XX.XX to the /home directory of the local computer:

scp root@121.43.XX.XX:/home/test001.txt /home

References