Example Secure Copy (SCP) Syntax

A short summary of the format for using scp secure copy to transfer files between a Linux computer and server and server to local computer.

To transfer a file from a remote server:

scp username@192.168.0.200:thefile.txt /local-path/directory

In the above the file shown is within the home directory of the account. Include a directory path as required. The examples below are relative to the home directory and to the file system root respectively:

scp username@192.168.0.200:remote-path/thefile.txt /local-path/directory
scp username@192.168.0.200:/remote-path/thefile.txt /local-path/directory

192.168..200 is the IP address used to reference the remote host. It may also be by domain name unique reference.

Enter the password associated with the account, when prompted.

To recursively transfer a directory from the same server

scp -r username@192.168.0.200:/remote-path/directory /local-path/directory

And the same options going the other way. First to transfer a file to the remote server.

scp -r /path/directory username@192.168.0.200:foobar.txt 

And to transfer a directory to the remote server

scp -r username@192.168.0.200:/local-path/directory /remote-path/directory

If the remote server uses a port other than the default, for example 12345 this can be specified with the -P option, example given below:

scp -P 12345 username@192.168.0.200:thefile.txt /path/directory

The table below is a summary of the options available

OptionFunction
-1Use version 1 of the SCP protocol
-2Use version 2 of the SCP protocol
-CUse gzip compression
-BInitiate the transfer without the request for a password
-i limitSet a bandwidth limit for the transfer (kb/s)
-o ssh_optionThe definition of concrete SSH options such as encryption
-P port numberThe port number to be used to connect to the remote server
-pPreserve the meta information of the files and directories (modification and access timings)
-qHide the progress bar
-rRecursively copy an entire directory and its sub-directories
-S programSpecify the program to be used to encrypt the connection

SCP can also be used to transfer files on the same computer – although maybe rsync is your preference.