1
0
mirror of https://github.com/moparisthebest/wget synced 2024-07-03 16:38:41 -04:00

Make wget capable of starting downloads from a specified position.

This patch adds an option `--start-pos' for specifying starting position
of a HTTP or FTP download.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
This commit is contained in:
Yousong Zhou 2014-03-19 23:42:04 +08:00 committed by Giuseppe Scrivano
parent 43c89ab7a5
commit dfa1f4e064
8 changed files with 51 additions and 3 deletions

View File

@ -1,3 +1,7 @@
2014-02-10 Yousong Zhou <yszhou4tech@gmail.com>
* wget.texi: Add documentation for --start-pos.
2013-12-29 Giuseppe Scrivano <gscrivan@redhat.com>
* wget.texi: Update to GFDL 1.3.

View File

@ -701,6 +701,22 @@ 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.
@cindex offset
@cindex continue retrieval
@cindex incomplete downloads
@cindex resume download
@cindex start position
@item --start-pos=@var{OFFSET}
Start downloading at zero-based position @var{OFFSET}. Offset may be expressed
in bytes, kilobytes with the `k' suffix, or megabytes with the `m' suffix, etc.
@samp{--start-pos} has higher precedence over @samp{--continue}. When
@samp{--start-pos} and @samp{--continue} are both specified, wget will emit a
warning then proceed as if @samp{--continue} was absent.
Server support for continued download is required, otherwise @samp{--start-pos}
cannot help. See @samp{-c} for details.
@cindex progress indicator
@cindex dot style
@item --progress=@var{type}

View File

@ -1,3 +1,10 @@
2014-03-19 Yousong Zhou <yszhou4tech@gmail.com>
* init.c, main.c, options.h: Add option --start-pos for specifying
start position of a download.
* http.c: Utilize opt.start_pos for HTTP download.
* ftp.c: Utilize opt.start_pos for FTP retrieval.
2014-03-04 Giuseppe Scrivano <gscrivan@redhat.com>
* http.c (modify_param_value, extract_param): Aesthetic change.

View File

@ -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 >= 0)
restval = opt.start_pos;
else if (opt.always_rest
&& stat (locf, &st) == 0
&& S_ISREG (st.st_mode))

View File

@ -3121,6 +3121,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 >= 0)
hstat.restval = opt.start_pos;
else if (opt.always_rest
&& got_name
&& stat (hstat.local_file, &st) == 0

View File

@ -270,6 +270,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 },
@ -406,6 +407,9 @@ defaults (void)
opt.warc_cdx_dedup_filename = NULL;
opt.warc_tempdir = NULL;
opt.warc_keep_log = true;
/* Use a negative value to mark the absence of --start-pos option */
opt.start_pos = -1;
}
/* Return the user's home directory (strdup-ed), or NULL if none is

View File

@ -276,6 +276,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 },
@ -485,6 +486,8 @@ Download:\n"),
existing files (overwriting them).\n"),
N_("\
-c, --continue resume getting a partially-downloaded file.\n"),
N_("\
--start-pos=OFFSET start downloading from zero-based position OFFSET.\n"),
N_("\
--progress=TYPE select progress gauge type.\n"),
N_("\
@ -1323,12 +1326,13 @@ for details.\n\n"));
_("WARC output does not work with --spider.\n"));
exit (1);
}
if (opt.always_rest)
if (opt.always_rest || opt.start_pos >= 0)
{
fprintf (stderr,
_("WARC output does not work with --continue, "
"--continue will be disabled.\n"));
_("WARC output does not work with --continue or"
" --start-pos, they will be disabled.\n"));
opt.always_rest = false;
opt.start_pos = -1;
}
if (opt.warc_cdx_dedup_filename != 0 && !opt.warc_digests_enabled)
{
@ -1350,6 +1354,14 @@ for details.\n\n"));
exit (1);
}
if (opt.start_pos >= 0 && opt.always_rest)
{
fprintf (stderr,
_("Specifying both --start-pos and --continue is not "
"recommended; --continue will be disabled.\n"));
opt.always_rest = false;
}
if (!nurl && !opt.input_filename)
{
/* No URL specified. */

View File

@ -116,6 +116,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. */