04 May 2010

Using SCP in UNIX

Secure file transfers to and from local or remote systems can be initiated with the SCP UNIX command.

To use the scp command to copy files between systems, use the following command:

scp filename1 userid@hostname:filename2
where filename1 is the file on the local system that you wish to copy, userid@hostname is the userid and hostname where you wish to copy it, and filename2 is the name you want to call the file on the remote system. For example:

scp myfile jdoe@terpconnect.umd.edu:myfile
Note: scp may also be used to copy files from a remote system to a local system. To do this in the first example above, reverse the order of filename1 and userid@hostname:filename2.

When this command is typed on the Glue system, it will copy the file to the TerpConnect system.

When you issue the command, you'll be prompted for the password on the remote system. You will then be given the stats of the transfer. Pay attention to the second item on the stat line; it's how much of the file got transferred (you want to see 100%). For example:

scp myfile jdoe@terpconnect.umd.edu:myfile
jdoe@terpconnect.umd.edu's password:
myfile 100% |***************************| 1232 00:00
The password will not show up when typed. The statistics indicate the percentage of the file that was transferred, the size of the file, and the estimated time to transfer the file (in this case, immediate). The scp command gives you three chances to get the password right before it aborts the connection.

To use the scp command to copy directories between systems, use the following command:

scp -r directoryname userid@hostname:directoryname2
where directoryname is the directory on the local system you wish to copy, userid@hostname is the userid and hostname where you wish to copy it, and directoryname2 is the name you want to call the file on the remote system. For example:

scp -r mydirectory jdoe@terpconnect.umd.edu:mydirectory
Note: scp may also be used to copy directories from a remote system to a local system. To do this in the first example above, reverse the order of directoryname and userid@hostname:directoryname2.

When this command is typed on the Glue system, it will copy the directory and all of its contents to the TerpConnect system.

The most common way to display help is at a UNIX prompt. Before you issue the scp command you can receive help at the UNIX prompt. An on-line UNIX manual is available for detailed help on scp. To access the manual information about scp, type the following at the UNIX system prompt:

man scp

No comments: