In this post, we'll learn how to use
rsync to copy large file of data, from local to remote and vice versa.
Copy File Using
Copying file using
scp is easy. Below is an example of how to transfer files between local and remote.
# copy from local to remote $ scp ~/file.txt email@example.com:/home/novalagung/ # copy from remote to local $ scp firstname.lastname@example.org:/home/novalagung/file.txt ~/
Basically, by using
scp, copying file is pretty much done. But, if the connection is not good enough and the file size is quite big, it'll be a problem.
Just imagine, you are transferring a file from your local with the size of 10GB, and after waiting for few hours, the transfer disconnected.
There is a solution to solve this kind of problem, by using
Copy File Using
rsync is a utility for efficiently transferring and synchronizing files across computer systems, by checking the timestamp and size of files. It is commonly found on Unix-like systems and functions as both a file synchronization and file transfer program
rsync is used for synchronizing and transferring files. It has a lot of advantages compared to
Good for copying multiple and large files, the process is faster compared to
scp. It's because
rsyncuse algorithm called delta compression, that are designed for minimizing network usage.
Because the main purpose of
rsyncis for both transferring and synchronizing files, it has many useful features. One if them is the capability to resume previous unsuccessful transfers.
rsync depends on
ssh to make the transferring process secure.
rysncis a standard utility included on Linux & Mac OS, so no need to install anything
Below is an example of
rsync transfer file command.
# copy from local to remote $ rsync -avz ~/file.txt email@example.com:/home/novalagung/ # copy from remote to local $ rsync -avz firstname.lastname@example.org:/home/novalagung/file.txt ~/
-avz argument is required for faster transfer process.
-a is short of archive,
-v is verbose, and
-z is for compression.
Resume Previous Download
To be able to resume the previous transfer (in case the current transfer is failing, so we don't have to start over again) use
--partial. Also, put
--progress as an argument to show the transfer progress.
$ rsync -avz --partial --progress email@example.com:/home/novalagung/file.txt ~/
rsync will write the data that's being transferred into a temporary file, then later will be moved into destination place when it's complete. The temporary path directory can be changed by adding
$ rsync -avz \ --partial \ --partial-dir=/homee/novalagung/temp/ \ --progress \ firstname.lastname@example.org:/home/novalagung/file.txt ~/
There is another alternative, use
--inplace, it will make
rsync to not write the transferred data into a temporary file, instead, it'll be written directly on the destination file.
$ rsync -avz \ --inplace \ --progress \ email@example.com:/home/novalagung/file.txt \ ~/
rsync With Identity File
rsync with identity file, just add
-e argument with the value is ssh command like below:
$ rsync -e "ssh -i path/to/key" \ -avz \ --inplace \ --progress \ firstname.lastname@example.org:/home/novalagung/file.txt \ ~/