Sunday, June 19, 2016

Linux Utilities - Linux File Sharing Over Network Computers Using scp And rsync

http://www.linuxandubuntu.com/home/linux-utilities-linux-file-sharing-over-network-computers-using-scp-and-rsync

Linux Utilities - Linux File Sharing Over Network Computers Using scp And rsync
In this article we shall discuss about two powerful Linux utilities that are used for sharing file/folder to network computers that are scp and rsync. scp allows you to simply copy directories or files from/to any remote destination whereas the rsync, besides simply copying files also acts as a synchronising tool that would synchronise the changes between source and destination. The discussion below is about their usage and various parameters that can be used along with to increase speed and security.

What Is SCP?

The SCP is a network protocol based on the BSD, RCP protocol. It supports file transfer over a network computers using Secure Shell (SSH). With SCP a client can send files to another client or server on the same network. It can also request or Download files from a server.

If user wants to share multiple files over a network computer then there are two ways to accomplish that. User can either specify each file in the command and then provide the destination path. The second method is that user can save all the files in one folder and can share the entire folder over the network computer. Both the methods have been mentioned below. You can use anyone you like.

Install OpenSSH Server In Linux

OpenSSH is required for doing Linux data transfer over network. I noticed that it's not already installed in some Linux distributions so in that case, the commands result in errors. So install OpenSSH server before you go ahead and share files using SCP.
Install OpenSSH Server

Syntax - How To Share Files Over A Network Computer?

SCP Syntax
Example - If you want to share a file name "myMovieList.txt" to a remote host(192.168.1.102), you can use the following command based on the above syntax.
SCP Linux File Sharing
To copy file from remote machine to your local machine
Copy file from remote machine to local machine
To copy multiple files, provide space separated list of files and at the last destination path
SCP - Copy multiple files

Using SCP Parameters For More File Sharing Options

You can use scp command with certain optional parameters that help you in faster copying and/or secure data transfer.

r : To copy directory you have to use parameter r to recursively copy the contents.

​The r command makes it very simple to transfer multiple files contained in a single folder. It's one of the best methods to do quick and secure Linux file sharing over network computers.
'r' Parameter to copy folder to a host computer
P : To send out file on machine with different port

​By default, scp shares file over network computers through port 22. In many cases, you would want to use another port then you can P parameter to use another port for folder sharing.
'P' Parameter to share files on host computer through a different port
c : Change Encryption algorithm

By default, scp uses Triple-DES cipher to encrypt data before transferring it. You can use other ciphers like blowfish (which has higher performance over default one).
'c' Change Encryption Algorithm
C : To transfer even faster you can use compression parameter that would compress the data while transferring and auto decompress it on the destination.
NOTE: No need to decompress the file on the destination.

What Is rsync?

​Rsync is helpful in sharing files annd folders and synchronising files and folders. Unlike SCP, rsync transfers only differences between source and destination files/folders. It uses compression and decompression by default and hence is faster than SCP. Once you get familiar with it, it'll save your a lot of time.

Install rsync In Linux

Install rsync in Linux

Syntax To Sync Folder Between Network Computers

Syntax
With rsync user can synchronize two folders existing over network computers. To transfer/sync folder from local to remote host, use the following command -
Sync folder using rsync
​[a and r params preserve timestamp, owner, links etc and recursively syncs the files respectively].

​List of optional parameters are:

-z : compress data.
-a : preserve links, owner, timestamp etc.
-r : recursive.
--progress: show progress while transferring.
--include and --exclude : include or exclude pattern or files.
Example

only rsync files/folders starting with S.

--delete : delete the directory if it doesn't exist at source but exists at the destination.
--max-size : max transfer size limit. [eg: --max-size='2000k']
--remove-source-files : remove files at source after sync
--bwlimit : limit bandwidth for transfer [--bwlimit=1000] (limit by 1000 bps)
If you are unsure of rsync command result, you can also do dry run with command : --dry-run.

Conclusion

Both the linux utilities are useful in sharing files over network computers. rsync being more efficient since it transfers only differences and compressed data by default. That's all for now. You can explore man pages for more. Do leave suggestions, comments or questions in the comment section below.

No comments:

Post a Comment