How to resume interrupted download automatically in curl?

Bili the big picture Bili the big · Nov 1, 2013 · Viewed 44.5k times · Source

I'm working with curl in Linux. I'm downloading a part of a file in ftp server (using the -r option), but my connection is not good, it always interrupts. I want to write a script which resume download when I'm connected again.

I've used this command, but it's not working:

until curl -r 666-9999 -C - --retry 999 -o "path/to/file" "ftp:/path/to/remote/file"; do :; done

Answer

Jithin picture Jithin · Nov 17, 2017
curl -L -O your_url

This will download the file.

Now let's say your connection is interrupted;

curl -L -O -C - your_url

This will continue downloading from the last byte downloaded

From the manpage:

Use "-C -" to tell curl to automatically find out where/how to resume the transfer. It then uses the given output/input files to figure that out.