Scp

  • This page was last modified on February 21, 2011, at 10:51.
The (mt) Community Wiki is a collaborative project. Any (mt) Media Temple customer or employee may contribute. Not all articles and/or content have been tested for accuracy by (mt) Media Temple.

For officially moderated and tested articles, be sure to visit our KnowledgeBase.

From (mt) Community Wiki

Contents

scp is an SSH utility for copying files securely from one server to another, or from your local computer to your remote server (or vice versa). Once you become familiar with the syntax, it is typically faster and more reliable than FTP.

Examples

The basic syntax for scp is as follows:

scp user1@host1.net:/path/to/desired/file.txt user2@host2.com:/path/to/new/copy

Command breakdown

  • scp - Start a secure copy.

FROM

  • user1@host1.net:/path/to/desired/file.txt - All of the information for the server and file you want to copy FROM.
    • user1 - Username for the server that has the file.
    • host1.net - Name of the server that has the file.
    • /path/to/desired/file.txt - Full path to the file you want to copy. Must include the file name.
    • You can also use relative paths to the file you want to copy. For example, if you are currently in the directory that has the file, just put file.txt.

TO

  • user2@host2.com:/path/to/new/copy - All of the information for the server and directory you want to copy TO.
    • user2 - Username for the server that needs a copy of the file.
    • host2.com - Name of the server that needs a copy of the file.
    • /path/to/new/copy - Full path to the directory where you want to make a copy of the file.
    • You can also use relative paths from your home directory on this server. For example, if you want the file to be copied to your home directory, leave everything after the : blank.

If you are currently logged into your local computer or one of the servers (either the one you want to copy FROM, or the one you want to copy TO), you can skip the login part of the command for that server.

From local computer or local server to remote server

This will put a copy of a file that you already have on this computer on another server. Run this command in SSH from your local computer, or from the server that has the existing copy of the file:

scp /path/to/desired/file.txt user2@host2.com:/path/to/new/copy

You will be prompted for the password for user2@host2.com. Type the password, hit enter, and your upload should proceed.

From remote server to local computer or local server

This will copy a file that exists on a remote server on to your local computer or local server. Run this command in SSH from your local computer, or from the server that needs the copy of the file:

scp user1@host1.net:/path/to/desired/file.txt /path/to/new/copy

You will be prompted for the password for user1@host1.net. Type the password, hit enter, and your download should proceed.

From remote server to remote server

You can run this command in SSH from any location. It will log into a remote server, and copy a file from that server to a different remote server.

scp user1@host1.net:/path/to/desired/file.txt user2@host2.com:/path/to/new/copy

You will be prompted for the passwords for both user1@host1.net and user2@host2.com. Type each password at the prompt, hit enter, and your remote copy should proceed.

Copying entire directories

Use the -r flag to recursively copy a directory and its contents. Example:

scp -r user1@host1.net:/path/to/directory user2@host2.com:/path/to/new/copy

More scp information

See the scp Manual page for full information on this command.

Notes/Supplemental