Knowledge Base

How to transfer files using SCP (Secure Copy)

This article describes how to use SCP (Secure Copy) to transfer files quickly and securely from the command line.

What is SCP?

Secure Copy (SCP) is a protocol based on SSH (Secure Shell) that provides secure file transfers between two computers. With SCP, you can quickly transfer files using the command line, which is often faster and easier than using a client with a graphical interface. Additionally, you can use this command-line functionality in your own batch files and scripts to automate file transfers.

For information about how to securely transfer files using a client with a graphical interface, please see this article.

Using an SCP client

Follow the appropriate procedure below for your computer's operating system.

Windows operating systems

Microsoft Windows does not include an SCP client, so you must download one first. A2 Hosting recommends PSCP, a free program that you can download here.

PSCP is part of the PuTTY tool suite for Windows. For information about how to access your account using SSH and PuTTY, please see this article.

After you have downloaded the PSCP executable to your local computer, you should add the directory where pscp.exe is located to your path so you can run it from any directory. After you do this, you are ready to transfer files to and from your A2 Hosting account. To do this, follow these steps:

  1. Open a DOS command window. To do this, click Start, click Run, type cmd, and then press Enter.
  2. To upload a file to your A2 Hosting account, type the following command. Replace both occurrences of username with your A2 Hosting username, and example.com with your site's domain name. Additionally, replace file with the name of the file on your local computer that you want to upload, and replace destination with the destination directory on your A2 Hosting account:
    pscp -P 7822 file username@example.com:/home/username/destination
    • Make sure you use an uppercase P to specify the port number.
    • The default port for SSH (and therefore SCP) is 22. However, A2 Hosting uses a different port for security reasons.
  3. Type your password when you are prompted to do so. PSCP uploads the file to the destination directory that you specified.
  4. To download a file from your A2 Hosting account, type the following command. Replace both occurrences of username with your A2 Hosting username, and example.com with your site's domain name. Additionally, replace file with the name of the file on your A2 Hosting account that you want to download, and replace destination with the destination directory on your local computer:

    pscp -P 7822 username@example.com:/home/username/file destination
    To download the file to the current directory, type a period (.) for the destination.
  5. Type your password when you are prompted to do so. PSCP downloads the file to the destination directory that you specified.

    There are a few additional options that you may find useful when working with PSCP:

    • The -p option preserves the original file's attributes, such as modification and access times.
    • The -r option enables you to recursively copy entire directories. For example, if you want to download the entire public_html directory to the current directory on your local computer, type the following command:
      pscp -r -P 7822 [email protected]:/home/username/public_html .
    • To view a list of all PSCP options, type pscp at the command line.
Mac OS X and Linux operating systems

Both Mac OS X and Linux include the scp client program, so you do not have to download a special client. To use the scp program, follow these steps:

  1. Open a terminal window. The procedure to do this depends on your operating system and desktop environment.
    • On Mac OS X, click Applications, click Utilities, and then click Terminal.
  2. To upload a file to your A2 Hosting account, type the following command. Replace username with your A2 Hosting username, and example.com with your site's domain name. Additionally, replace file with the name of the file on your local computer that you want to upload, and replace destination with the destination directory on your A2 Hosting account:

    scp -P 7822 file username@example.com:~/destination
    • Make sure you use an uppercase P to specify the port number. Note that this is the opposite of the ssh client program, which uses a lowercase p to specify the port number.
    • The default port for SSH (and therefore SCP) is 22. However, A2 Hosting uses a different port for security reasons.
  3. Type your password when you are prompted to do so. Scp uploads the file to the destination directory that you specified.
  4. To download a file from your A2 Hosting account, type the following command. Replace username with your A2 Hosting username, and example.com with your site's domain name. Additionally, replace file with the name of the file on your A2 Hosting account that you want to download, and replace destination with the destination directory on your local computer:

    scp -P 7822 username@example.com:~/file destination
    To download the file to the current directory, type a period (.) for the destination.
  5. Type your password when you are prompted to do so. Scp downloads the file to the destination directory that you specified.

    There are a few additional options that you may find useful when working with scp:

    • The -p option preserves the original file's attributes, such as modification and access times.
    • The -r option enables you to recursively copy entire directories. For example, if you want to download the entire public_html directory to the current directory on your local computer, type the following command:
      scp -rP 7822 [email protected]:~/public_html .
    • To view the complete scp documentation, type man scp at the command line.

More Information

For more information about SCP, please visit http://en.wikipedia.org/wiki/Secure_copy.