How resume your interrupted at 99% scp operation

Imagine the sad scenario: you have started an scp operation of a 10GB file over a slow non-stable line.. time passes by.. slowly and painfully.. the file transfer is at 99% complete and… sundelly scp terminates with an error or because a line problem.

What do you do? you feel the urge to smash everything! but.. there is a simple way to continue the scp operation where it stopped, but how?. We can use rsync in place of scp (actually is a very good idea always to use rsync).

Lets simulate the scenario:

on the source computer run the following to create an 100MB file named ‘test’

$ head -c 100M </dev/urandom > test

on the computer that we want to transfer the ‘test’ file run the following

$ scp -l 800 user@source:~/test .
  • -l 800 parameter limits the download speed to 100KB/s in order to give us enough time to stop the download before it completes

Now before the transfer completes stop scp with ctrl+c or with any suitable way

$ scp -l 800 user@source:~/test .
user@source's password:
test 3% 3216KB 100.3KB/s 16:28 ETA^Cuser@source:~$

Now we have completed the 1st phase of our scenario, we have a corrupted file transfer on our computer, lets see how we can resume the file transfer where it stopped.

We go to the directory of the incomplete trasnfer and we enter the following

$ rsync --progress --append --partial -vz -e 'ssh -p 22' user@source:~/test .

We can see that the transfer continues where it stopped with the scp command.

After the transfer completion is always a good practice to verify the intergrity of the both files to ensure that the transfer completed without any corruptions

$ md5sum test
2d0434e2fc9868bed72c5dd5f0373393 test

if in both computers you see the same hash value then we can be sure that the file transfer completed succesfully.

DevOps engineer, loves Linux, Python, cats and Amiga computers

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store