Scp -- Secure File Transfer between UNIX machines
This article is composed of the following sections:
Scp is a utility which allows files to be copied between machines. Scp is an updated version of an older utility named Rcp. It works the same, except that information (including the password used to log in) is encrypted. Also, if you have set up your .shosts file to allow you to ssh between machines without using a password as described in help on setting up your .shosts file, you will be able to scp files between machines without entering your password.
The general form of the command is:
% scp source-specification destination-specification
where source-specification indicates which file or directory is to be copied, and destination-specification indicates where the copied material is to be placed.
Either the source or the destination may be on the remote machine; i.e., you may copy files or directories into the account on the remote system OR copy them from the account on the remote system into the account you are logged into.
% scp myfile xyz@sdcc7:myfile
To copy a directory, use the -r (recursive) option. Example:
% scp -r mydir xyz@sdcc7:mydir
The format for the remote specification (source or destination) is:
where filename is the name (path) of the file or directory relative to the home (login) directory on the remote system.
The format for file specification on the local system is just:
where fname is the name (path) relative to the current working directory on that system.
Just like the cp command, scp will overwrite an existing destination file. In addition, if the destination is an existing directory, the copied material will be placed beneath the directory.
- While logged into xyz on sdcc7, copy file "letter" into file "application" in remote account abc on sdcc3:
% scp letter abc@sdcc3:application
- While logged into abc on sdcc3, copy file "foo" from remote account xyz on sdcc7 into filename "bar" in abc:
% scp xyz@sdcc7:foo bar
- While logged into account xyz on sdcc7, copy file "garfield" from subdirectory "comix" into filename "fatcat" in subdirectory "stuff" in remote account abc on sdcc3:
% scp comix/garfield abc@sdcc3:stuff/fatcat
- While logged into account abc on sdcc3, copy file "garfield" from subdirectory "comix" of account xyz on sdcc7 into subdirectory "stuff" with the same name "garfield":
% scp xyz@sdcc7:comix/garfield stuff
- While logged into account abc on sdcc3 , copy subdirectory "Section" into a new subdirectory called "Section" in existing subdirectory "Chapter" in account xyz on sdcc7:
% scp -r Section xyz@sdcc7:Chapter
- From account abc on sdcc3, copy entire account to ir123 on iacs5. This needs to be done from the parent directory of the account to be moved.
% cd ..
% scp -r abc ir123@iacs5:abc
For more information about the scp (secure copy) command, check the on-line manual page for scp:
% man scp