Secure Copy Syntax Examples

Secure Copy (SCP) is a means of securely transferring files between hosts on a network. It is based on the Secure Shell (SSH) protocol. The command line scp program, which is provided in most SSH implementations, is the secure analog of the rcp command.

The syntax for scp is typically similar to that of the cp command.


Copying from a remote host to your local host:

# Copy a file
scp /path/to/local/targetfile

# Copy a directory
scp -r /path/to/local/targetfolder


Copying from your local host to a remote host:

# Copy a file
scp sourcefile.txt

# Copy a directory
scp -r sourcefolder


SSH runs over port 22 by default. If your remote host uses a port other than that default, you can specify the port using the -P flag:

# Copy a file from your local host to a remote host using port 2222
scp -P 2222 sourcefile.txt


References / Resources

Leave a Reply