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 computer 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 a 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 the user can save all the files in one folder and can share the entire folder over the network computer. Both 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 the 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 For Debian or Ubuntu based Linux distributions - sudo apt-get install openssh-server For Fedora Based Linux distributions sudo dnf install openssh-server

Syntax – How To Share Files Over A Network Computer?

SCP Syntax scp [optionalParameters] source destination 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 scp myMovieList.txt [email protected]:/home/savan.patel/ To copy file from remote machine to your local machine

To copy multiple files, provide space separated list of files and at the last destination path

SCP – Copy multiple files scp file1 file2 file3 [email protected]:/home/savan.patel/

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 the folder to a host computer For example to copy blogs folder to remote machine, you would use command, scp -r /home/savan/blog [email protected]:/home/savan.patel/

P: To send out file on the 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 scp -P8080 -r /home/savan/blog [email protected]:/home/savan.patel/

​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 scp -c blowfish movieList.txt [email protected]:/home/savan.patel/

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 and folders and synchronizing 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 you a lot of time.

Install rsync In Linux

For Debian or Ubuntu based Linux distributions - sudo apt-get install rsync For Fedora based Linux distributions sudo dnf install rsync

Syntax To Sync Folder Between Network Computers

Syntax rsync [optionalParameters] source destination

With rsync user can synchronize two folders existing over network computers. To transfer/sync folder from local to the remote host, use the following command –

Sync folder using rsync rsync -ar /home/savan/backup/ [email protected]:/home/savan.patel/backup/ ​[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.

​

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 a dry run with the command : –dry-run.

Conclusion