DEV Community

Cover image for Curl able to resume.
Michel Sánchez Montells
Michel Sánchez Montells

Posted on

Curl able to resume.

If you don't want to read:

Spolier

curl -L -O -C - 'https://internet-address/ubuntu-22.04.2-desktop-amd64.iso'
Enter fullscreen mode Exit fullscreen mode

Some context

Writing this post with the goal knowing where to find out this again in the future and maybe help someone out there.

You can stay in the situation of downloading big file from internet using curl. And you can face the situation of bad connectivity and the downloading is interrupted continuously before ending and you need to start again.

Then you would like to be able of resume from the last byte.

The default or first curl command will looks like:

curl command

curl --header 'Host: mirrors.ircam.fr'
     --header 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36' 
     --header 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7' 
     --header 'Accept-Language: es-CU,es;q=0.9,en-US;q=0.8,en;q=0.7,es-419;q=0.6' 
     --header 'Referer: https://ubuntu.com/' 
     'https://mirrors.ircam.fr/pub/ubuntu/releases/22.04.2/ubuntu-22.04.2-desktop-amd64.iso' 
      -L -o 'ubuntu-22.04.2-desktop-amd64.iso'

This command will be downloading with file name ubuntu-22.04.2-desktop-amd64.iso however once the connection get closed after 600Mb of 3Gb if you retry the same command the downloading will start from 0.

Solution

curl command

curl --header 'Host: mirrors.ircam.fr' 
     --header 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36' 
     --header 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7' 
     --header 'Accept-Language: es-CU,es;q=0.9,en-US;q=0.8,en;q=0.7,es-419;q=0.6' 
     --header 'Referer: https://ubuntu.com/' 
     -L -O -C - 'https://mirrors.ircam.fr/pub/ubuntu/releases/22.04.2/ubuntu-22.04.2-desktop-amd64.iso'`

The parameter -C will ensure that the file is downloading like resuming, starting with the proper offset.
The parameter -O will assing to the downloaded local file name the same name of the remote file.

Top comments (0)