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.
Examples
Copying from a remote host to your local host:
# Copy a file
scp username@remotehost.com:sourcefile.txt /path/to/local/targetfile
# Copy a directory
scp -r username@remotehost.com:sourcefolder /path/to/local/targetfolder
Copying from your local host to a remote host:
# Copy a file
scp sourcefile.txt username@remotehost.com:/path/to/remote/targetfile
# Copy a directory
scp -r sourcefolder username@remotehost.com:/path/to/remote/targetfolder
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 username@remotehost.com:/path/to/remote/targetfile