63

How do I resume a partially downloaded file using a Linux commandline tool?

I downloaded a large file partially, i.e. 400 MB out of 900 MB due to power interruption, but when I start downloading again it resumes from scratch. How do I start from 400 MB itself?

3
  • 5
    What commandline did you use to download the file in the first place?
    – Anthon
    Nov 4, 2014 at 10:34
  • 3
    Please don't answer in a comment, update your incomplete question.
    – Anthon
    Nov 4, 2014 at 11:22
  • 1
    If you are using curl, you should search the man page for the -C option.
    – HalosGhost
    Nov 4, 2014 at 14:22

4 Answers 4

82

Since you didn't specify, I'm assuming you are using wget to download the file. If this is the case, try using it with the -c option (e.g. wget -c <URL>).

Please notice that in case the protocol used is ftp (the URL looks like ftp://...) there is a chance the remote server uses an old/ancient ftp daemon which doesn't support resuming downloads (newer ftp daemons do support it for more than a decade anyway, so this is just a small chance). If this is the case, though, you may be out of luck. In the other hand you should have no issues if the protocol used is http. (UPDATE: According to other experts (including Gilles in the comments below), resuming while using http is also subject to the server support, so this apply to both ftp and http).

Good luck.

4
  • 8
    HTTP downloads can only be resumed if the server supports it, and that's rarer than with FTP servers. Nov 4, 2014 at 18:10
  • 1
    wget -c http:... has worked the 3 or 4 servers I've tried it on.
    – Bob Stein
    May 28, 2015 at 1:36
  • 3
    @Gilles: Actually, this is now a common option with any static content from servers newer than ~2010 (in other words, most servers allow Range requests for static files by default). For dynamically generated data, this is indeed rare. Feb 3, 2017 at 13:06
  • For the sake of completeness: the tagline for the option from the wget manpage: -c, --continue Continue getting a partially-downloaded file
    – Wumms
    Aug 1, 2020 at 9:05
4

If there are multiple files to download and the download was interrupted at one of the files then -c along with -r can help.

wget -c -r <url>

This command will check all the files and download only the ones which are incomplete or not downloaded. I had to download more than a hundred large files and used the following options just to be nice to the server:

wget -c -r -np -k --wait=15 --limit-rate=50K <url>

2

curl -C -

If you want to use curl instead of wget:

curl -C - -o index.html https://example.com

From the man:

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.

We can test it out quick and dirty with:

printf asdf > index.html
curl -C - -o index.html https://example.com

and now index.html starts with:

asdfctype html>
<html>

so clearly it skipped the first 4 characters <!do when downloading since the file already had them, without the asdf the file would have been:

<!doctype html>
<html>

Serve capability check: accept-ranges: bytes

Incremental download works on example.com because according to:

curl -I https://example.com

the server returns the:

accept-ranges: bytes

HTTP header, which means curl can ask for ranges: request to start from the middle:

Tested on Ubuntu 23.10, curl 8.2.1.

0

I know what the original question mean, and the answer is not wget -c ...

The scenario can be described like this:

# Start mirroring a site
wget -m http://...
# 400MB later wget died or interrupted,
# don't know where it left off, don't care,
# just want to get the remaining 100MB without getting the first 400MB again
wget -nc -r -l inf --no-remove-listing http://...

Options "-r -l inf --no-remove-listing" is equivalent to -m without the -N parameter. Adding the -nc parameter avoid saving the first 400MB already in your hard drive.

1
  • I didn't try this method... so I'm not saying it is right or wrong. However, wget -c worked for me. I purposely killed the transfer early, and saw it resume right where it left off.
    – Dan H
    Mar 4 at 18:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .