Linux Utilities – Linux File Sharing Over Network Computers Using scp And rsync
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
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
scp [optionalParameters] source destination
scp myMovieList.txt firstname.lastname@example.org:/home/savan.patel/
To copy file from remote machine to your local machine
scp email@example.com:/home/savan/ myMovieList.txt
scp file1 file2 file3 firstname.lastname@example.org:/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.
For example to copy blogs folder to remote machine, you would use command, scp -r /home/savan/blog email@example.com:/home/savan.patel/
P: To send out file on the machine with different portBy 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.
scp -P8080 -r /home/savan/blog firstname.lastname@example.org:/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).
scp -c blowfish movieList.txt email@example.com:/home/savan.patel/
scp -C movieList.txt firstname.lastname@example.org:/home/savan.patel/
What Is rsync?
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
rsync [optionalParameters] source destination
rsync -ar /home/savan/backup/ email@example.com:/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.
–progress: show progress while transferring.
–include and — exclude: include or exclude pattern or files.
rsync -ar /home/savan/backup/ --include 'S*' --exclude '*' firstname.lastname@example.org:/home/savan.patel/backup/
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.