Based on the Secure Shell (SSH) protocol, Secure Copy (SCP) is a method for transferring files securely between two computers. You can transfer between a local host and a remote host, or between two remote hosts.
The format of the scp command is as follows:
scp [flags] [source location] [destination location]
The first use for scp is obviously to download a file from a remote server.
scp remoteuser@remotehost:remotefile localfile
The exact opposite of downloading, uploading just reverses the order of the source,destination paths.
scp localfile remoteuser@remotehost:remotefile
In this scenario your local machine only tells the two remote hosts to perform the transfer. The data itself is transferred directly between the two remote hosts. For this reason it is important that they are able to communicate directly to each other.
scp remoteuser1@remotehost1:remotefile1 remoteuser2@remotehost2:remotefile2
In addition to the basic operations, here are some tips and tricks for using scp.
This is more of a general tip but a useful one regardless.
Using a single dot (.) in place of a file path is equivalent to specifying the current local directory. In addition specifying two dots (..) gives the parent directory of the current local directory.
No not the little viking dude. Like ssh you can use the asterix symbol to specify all files within a directory like this.
//copies all files inside "/some/directory/" to the current local directory
scp remoteuser@remotehost:/some/directory/* .
In addition to supporting the asterix, you can also specify the "-r" recursive flag to recursively copy all files and directories with the specified directory.
scp -r remoteuser@remotehost:/some/directory/* .
While not too common, it may happen that you need to use scp on a host that has it configured to be on a different port number. In this situation you use the "-P" flag to specify the port number to use.
Unlike ssh, we use the uppercase "-P" flag not the lowercase "-p", and this flag must be directly in front of the (remote) host. The reason for this is because scp can be used to transfer between two remote hosts it needs to know which host is operating on with port number.
scp -P newport remoteuser@remotehost:/some/directory/* .