There is always a scenario where we sometimes encounter the transfer of files to be broken because of some reason. The reasons could be different, unless it is not that you explicitly closed the particular connection or process, it can be recovered.
It should also be noted that the scp command doesn’t have a resume option, and the only option is to simply start copying the files from the beginning and overwrite the existing files. The process of doing this again and again because of the ssh disconnection can be very annoying and time consuming.
Linux does provide us with a command utility that we can make use of instead of the ssh and the utility is named as Rsync.
With the help of the Rsync command utility we can easily resume the process of the files that were partially transferred over SSH.
In order to make use of Rsync, we must first understand what it is and what are the benefits of using it.
Rsync is a Linux command line utility that is used to transfer and copy files or folders to and from local to remote systems. It offers a large number of options that we can make use of, and it is very flexible to use as well. It is famous for its delta-transfer algorithm, which helps in reducing the amount of data sent over the network by sending only the differences between the source files and the existing files in the destination.
Rsync mainly finds its use for backups and mirroring and is basically an improved version of the copy command.
Now, before making use of the Rsync utility we should Install it first. Several commands are mentioned below that explain how to install the Rsync utility on your machine.
sudo apt-get install rsync
sudo dnf install rsync
Now let’s see an example where I will try to copy a particular file from my machine to some other remote machine.
scp goAgent.tar.gz firstname.lastname@example.org:/home/Documents/
In the above case, I am making use of the scp command, which is short for secure copy, that allows us to copy files from local to remote and vice versa.
I will deliberately cancel the above process with the help of the CTRL + C
Now if I check the file in the remote machine, this is what I will see −
goAgent.tar.gz 51% 399MB 26.2MB/s 00:39 ETA^c
Now just run the Rsync command like this and your process will resume.
rsync -P -rsh=ssh goAgent.tar.gz email@example.com:/home/Documents/
goAgent.tar.gz 100% 840.00M 26.2MB/s 0:00:43