>From f7266cc18fbea1d07b25c1bd25662a5a71920520 Mon Sep 17 00:00:00 2001 From: Yousong Zhou Date: Fri, 20 Dec 2013 23:17:43 +0800 Subject: [PATCH v3] Make wget capable of starting download from a specified position. This patch adds an option `--start-pos' for specifying starting position of a download, both for HTTP and FTP. When specified, the newly added option would override `--continue'. Apart from that, no existing code should be affected. Signed-off-by: Yousong Zhou --- v2 -> v3 Fix a typo and add description text for the new option into the usage output. Thank Darshit Shah for the suggestions. v1 -> v2 It was kindly pointed out by Darshit Shah that server support for resuming download is required, so adding this into doc/wget.texi. doc/ChangeLog | 4 ++++ doc/wget.texi | 17 +++++++++++++++++ src/ChangeLog | 9 +++++++++ src/ftp.c | 2 ++ src/http.c | 2 ++ src/init.c | 1 + src/main.c | 3 +++ src/options.h | 1 + 8 files changed, 39 insertions(+), 0 deletions(-) diff --git a/doc/ChangeLog b/doc/ChangeLog index 3b05756..df103c8 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,7 @@ +2013-12-21 Yousong Zhou + + * wget.texi: Add documentation for --start-pos. + 2013-10-06 Tim Ruehsen * wget.texi: add/explain quoting of wildcard patterns diff --git a/doc/wget.texi b/doc/wget.texi index 4a1f7f1..87fef7c 100644 --- a/doc/wget.texi +++ b/doc/wget.texi @@ -701,6 +701,23 @@ Another instance where you'll get a garbled file if you try to use Note that @samp{-c} only works with @sc{ftp} servers and with @sc{http} servers that support the @code{Range} header. address@hidden offset address@hidden continue retrieval address@hidden incomplete downloads address@hidden resume download address@hidden start position address@hidden address@hidden +Start the download at position @var{OFFSET}. Offset may be expressed in bytes, +kilobytes with the `k' suffix, or megabytes with the `m' suffix. + +When specified, it would override the behavior of @samp{--continue}. When +using this option, you may also want to explicitly specify an output filename +with @samp{-O FILE} in order to not overwrite an existing partially downloaded +file. + +Server support for resuming download is needed, otherwise @samp{--start-pos} +cannot help. See @samp{-c} for details. + @cindex progress indicator @cindex dot style @item address@hidden diff --git a/src/ChangeLog b/src/ChangeLog index 42ce3e4..ab8a496 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +2013-12-21 Yousong Zhou + + * options.h: Add option --start-pos to specify start position of + a download. + * main.c: Same purpose as above. + * init.c: Same purpose as above. + * http.c: Utilize opt.start_pos for HTTP download. + * ftp.c: Utilize opt.start_pos for FTP retrieval. + 2013-11-02 Giuseppe Scrivano * http.c (gethttp): Increase max header value length to 512. diff --git a/src/ftp.c b/src/ftp.c index c2522ca..c7ab6ef 100644 --- a/src/ftp.c +++ b/src/ftp.c @@ -1632,6 +1632,8 @@ ftp_loop_internal (struct url *u, struct fileinfo *f, ccon *con, char **local_fi /* Decide whether or not to restart. */ if (con->cmd & DO_LIST) restval = 0; + else if (opt.start_pos) + restval = opt.start_pos; else if (opt.always_rest && stat (locf, &st) == 0 && S_ISREG (st.st_mode)) diff --git a/src/http.c b/src/http.c index 754b7ec..a354c6b 100644 --- a/src/http.c +++ b/src/http.c @@ -3098,6 +3098,8 @@ Spider mode enabled. Check if remote file exists.\n")); /* Decide whether or not to restart. */ if (force_full_retrieve) hstat.restval = hstat.len; + else if (opt.start_pos) + hstat.restval = opt.start_pos; else if (opt.always_rest && got_name && stat (hstat.local_file, &st) == 0 diff --git a/src/init.c b/src/init.c index 84ae654..7f7a34e 100644 --- a/src/init.c +++ b/src/init.c @@ -271,6 +271,7 @@ static const struct { { "showalldnsentries", &opt.show_all_dns_entries, cmd_boolean }, { "spanhosts", &opt.spanhost, cmd_boolean }, { "spider", &opt.spider, cmd_boolean }, + { "startpos", &opt.start_pos, cmd_bytes }, { "strictcomments", &opt.strict_comments, cmd_boolean }, { "timeout", NULL, cmd_spec_timeout }, { "timestamping", &opt.timestamping, cmd_boolean }, diff --git a/src/main.c b/src/main.c index 19d7253..469e782 100644 --- a/src/main.c +++ b/src/main.c @@ -281,6 +281,7 @@ static struct cmdline_option option_data[] = { "server-response", 'S', OPT_BOOLEAN, "serverresponse", -1 }, { "span-hosts", 'H', OPT_BOOLEAN, "spanhosts", -1 }, { "spider", 0, OPT_BOOLEAN, "spider", -1 }, + { "start-pos", 0, OPT_VALUE, "startpos", -1 }, { "strict-comments", 0, OPT_BOOLEAN, "strictcomments", -1 }, { "timeout", 'T', OPT_VALUE, "timeout", -1 }, { "timestamping", 'N', OPT_BOOLEAN, "timestamping", -1 }, @@ -490,6 +491,8 @@ Download:\n"), N_("\ -c, --continue resume getting a partially-downloaded file.\n"), N_("\ + --start-pos=OFFSET start the download from position OFFSET.\n"), + N_("\ --progress=TYPE select progress gauge type.\n"), N_("\ -N, --timestamping don't re-retrieve files unless newer than\n\ diff --git a/src/options.h b/src/options.h index ad89627..9ba1760 100644 --- a/src/options.h +++ b/src/options.h @@ -115,6 +115,7 @@ struct options bool ask_passwd; /* Ask for password? */ bool always_rest; /* Always use REST. */ + wgint start_pos; /* Start position of a download. */ char *ftp_user; /* FTP username */ char *ftp_passwd; /* FTP password */ bool netrc; /* Whether to read .netrc. */ -- 1.7.2.5