curlzsh

Make cURL resume interrupted downloads using the 'until' loop


Here is a solution how to make cURL automatically resume interrupted downloads, from the 2013 blog post by Juan Nunez-Iglesias:

export ec=18; while [ $ec -eq 18 ]; do curl -O -C - http://site.xyz/file.zip; export ec=$?; done

It has been posted several times here, both the original version and with slight changes inside the while loop.

The changes inside the while loop were introduced by different people to make the script more robust.

In March, Helder Magalhães suggested to replace the while loop in the original Juan's version with until:

This solution can be further simplified using until unstead. See related thread.

Though I'm not really good in using cURL or in shell scripting, I would try to write it myself, but the problem to write it myself is not the script itself but the lack of understanding how to properly test it.

Could somebody show how to implement Helder's idea? And does it really make script more robust?

I use Zsh.


Solution

  • Here you go:

    until curl ...; do
      [ $? -eq 18 ] || break
    done