Huge Discounts on Mobiles, Books, Cameras, Computers etc: @Flipkart
Flipkart.com
Showing posts with label How to copy directories remotely in Linux. Show all posts
Showing posts with label How to copy directories remotely in Linux. Show all posts

Friday, November 16, 2007

How to copy directories remotely in Linux

FTP/SFTP has commands like get and mget (put/mput) but they work only on a file or multiple files. Both commands cannot handle a directory. So how do you remotely copy a directory in linux, especially say between two Linux machines?

SCP - Secure Copy Protocol
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 /home/file1 root@mysystem.com:/root/file1

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 (eg: 100%).

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.

scp root@mysystem.com:/root/file1 /home/file1


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 /home/ root@mysystem.com:/root/dir1

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.

scp -r root@mysystem.com:/root/dir1 /home/