Downloading files from the web can sometimes be interrupted due to various reasons, such as connection timeouts or abrupt system restarts. In such cases, downloading the entire file again can be time-consuming, especially if the file is large. Fortunately, with cURL, you can resume an interrupted download, provided the web server supports the HTTP Range header.

Many modern web servers support the HTTP Range header, allowing clients to request specific portions of a file. This functionality is invaluable when you want to continue downloading a file from where it was interrupted.

However, always be cautious and verify the integrity of the downloaded file, especially if it's a software package, as partial downloads can lead to corrupted files.

The ability to resume depends on the server's support for the HTTP Range header. Not all servers may support this feature. If you find that the resume feature doesn't work, it's likely that the server doesn't support it or is configured not to allow range requests.

Steps to resume interrupted download using cURL:

  1. Open the terminal.
  2. Begin downloading a file using cURL.
    $ curl -O
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
      0 10.0G    0 44.5M    0     0  4654k      0  0:37:32  0:00:09  0:37:23 7196k^C
  3. If the download is interrupted, simply re-initiate the download with the -C- flag.
    $ curl -C - -O
    ** Resuming transfer from byte position 52240384
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
      0  9.9G    0 42.9M    0     0  7101k      0  0:24:29  0:00:06  0:24:23 9899k

    cURL will check the local file for its size and will resume the download from where it was interrupted.

  4. Once the download is complete, verify the file's integrity by comparing the file size or using checksums.
    $ ls -l
    -rw-r--r--@ 1 user  group  10737418240 Sep  9 21:05
  5. If you encounter errors, you may need to reinitiate the download without the -C- flag to start from the beginning.
    $ curl -O
  6. Store your downloaded file in your preferred directory.

Always ensure the integrity of the downloaded files, especially if they're executable or if they're intended for production use. Corrupted or partial files can lead to unexpected behavior.

Discuss the article:

Comment anonymously. Login not required.