File downloads can get interrupted due to unstable network connections. When downloading large files, restarting the download from the beginning wastes both time and bandwidth. cURL provides a solution by allowing the user to continue the download from where it stopped.

The ability to resume a download depends on the server's support for the HTTP Range header. This allows cURL to request only the remaining part of the file. However, if the server doesn't support this header, the download will restart from the beginning.

Using cURL, you can resume single file downloads or multiple interrupted downloads. For multiple files, cURL will skip the already downloaded files and resume the rest. This ensures efficient data transfer and saves bandwidth during interrupted downloads.

Steps to resume a download using cURL:

  1. Open the terminal.
  2. Start the file download using cURL.
    $ curl -O https://www.example.com/largefile.zip
    % 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. Stop the download manually or let it fail due to connection issues.
  4. Use the -C - option to resume the download.
    $ curl -C - -O https://www.example.com/largefile.zip
    ** 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

    This will only work if the server supports the HTTP Range header.

  5. Verify the file's integrity by checking the file size or using checksums.
    $ ls -l largefile.zip
    -rw-r--r--@ 1 user  group  10737418240 Sep  9 21:05 largefile.zip
  6. If errors occur, restart the download without using the -C - option.
  7. Remove incomplete or corrupted files created by failed downloads.
    $ rm largefile.zip.part

    Some systems or tools append .part or similar extensions to indicate partial downloads.

Discuss the article:

Comment anonymously. Login not required.