Remote file copy using Secure Copy

The secure shell program also comes with a secure copy program that can be used to copy files to/from remote machines. The command to use is scp. For simple usage, the scp program takes two arguments:

  1. the file we want to copy/send
  2. the place we want to copy/send to (optionally with a new name)

The basic syntax would be:

scp sourcepath/filename destinationpath/optionalNewFilename

Note that the first argument is the FROM part and the second is the TO part.

To copy a directory, use the recursive option -r as shown below:

scp -r sourcepath/directoryname destinationpath/optionalNewDirectoryname

To specify a remote machine, use the internet hostname of the machine in the path (along with user name on remote machine if different from the local machine). For example:

scp -r program4 USERNAME@onyx.boisestate.edu:workspace/

copies the local directory named program4 to under the workspace directory on theonyx server. Note the required colon `:' after the edu. The file path on the remote machine goes after that. If the second argument was USERNAME@onyx.boisestate.edu: (that is, nothing after the colon), then it would copy the program4 directory to user's home directory on onyx. Here the USERNAME is the login user name on the remote server. We can skip this part if the user name on the local system is the same as on the remote onyx server.

Note that you would use the scp command only on your local system to either download file(s) from onyx or to upload file(s) to onyx. You cannot use it on onyx to access your local system for two reasons: (1) your local system is usually behind a firewall and not accessible via secure shell or secure copy (2) the server we are connecting to needs to run the secure shell service to allow clients to connect to it. Your laptop or desktop would typically not have this service enabled (due to security concerns).



Subsections