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 [email protected]:filename2

where filename1 is the file on the local system that you wish to copy, [email protected] 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 [email protected]:/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 [email protected]:filename2.

scp [email protected]:/root/file1 /home/file1


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

scp -r directoryname [email protected]:directoryname2

where directoryname is the directory on the local system you wish to copy, [email protected] 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/ [email protected]:/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 [email protected]:directoryname2.

scp -r [email protected]:/root/dir1 /home/

Big thanks to this blog author

Latest blog

Web Analytics