diff -rupN wget-1.13.4.original/src/ftp.c wget-1.13.4-limitsize/src/ftp.c --- wget-1.13.4.original/src/ftp.c 2011-09-13 11:05:12.000000000 +0300 +++ wget-1.13.4-limitsize/src/ftp.c 2012-03-28 00:50:09.731942900 +0300 @@ -1747,6 +1747,14 @@ ftp_retrieve_list (struct url *u, struct err = RETROK; dlthis = true; + + if ((f->type == FT_PLAINFILE) && opt.limit_size && (f->size > opt.limit_size)) + { + logprintf (LOG_VERBOSE, _("%s -- remote file size (%s) "), quote (con->target), human_readable(f->size)); + logprintf (LOG_VERBOSE, _("is bigger than limit-size (%s) option -- not retrieving.\n"), human_readable(opt.limit_size)); + dlthis = false; + } + if (opt.timestamping && f->type == FT_PLAINFILE) { struct_stat st; diff -rupN wget-1.13.4.original/src/http.c wget-1.13.4-limitsize/src/http.c --- wget-1.13.4.original/src/http.c 2011-09-07 13:58:01.000000000 +0300 +++ wget-1.13.4-limitsize/src/http.c 2012-03-28 01:24:23.114389600 +0300 @@ -2377,6 +2377,25 @@ read_header: } } + if (opt.limit_size && (contlen > opt.limit_size)) + { + logprintf (LOG_VERBOSE, _("%s -- remote file size (%s) "), quote (u->path), human_readable(contlen)); + logprintf (LOG_VERBOSE, _("is bigger than limit-size (%s) option -- not retrieving.\n"), human_readable(opt.limit_size)); + + /* this piece of code is copypasted from the code below... */ + + /* In case the caller inspects. */ + hs->len = contlen; + hs->res = 0; + /* Mark as successfully retrieved. */ + *dt |= RETROKF; + xfree_null (type); + CLOSE_INVALIDATE (sock); /* would be CLOSE_FINISH, but there + might be more bytes in the body. */ + xfree (head); + return RETRUNNEEDED; + } + if (statcode == HTTP_STATUS_RANGE_NOT_SATISFIABLE || (!opt.timestamping && hs->restval > 0 && statcode == HTTP_STATUS_OK && contrange == 0 && contlen >= 0 && hs->restval >= contlen)) diff -rupN wget-1.13.4.original/src/init.c wget-1.13.4-limitsize/src/init.c --- wget-1.13.4.original/src/init.c 2011-08-19 13:06:20.000000000 +0300 +++ wget-1.13.4-limitsize/src/init.c 2012-03-27 23:57:02.270630500 +0300 @@ -194,6 +194,7 @@ static const struct { { "iri", &opt.enable_iri, cmd_boolean }, { "keepsessioncookies", &opt.keep_session_cookies, cmd_boolean }, { "limitrate", &opt.limit_rate, cmd_bytes }, + { "limitsize", &opt.limit_size, cmd_bytes }, { "loadcookies", &opt.cookies_input, cmd_file }, { "localencoding", &opt.locale, cmd_string }, { "logfile", &opt.lfilename, cmd_file }, diff -rupN wget-1.13.4.original/src/main.c wget-1.13.4-limitsize/src/main.c --- wget-1.13.4.original/src/main.c 2011-09-06 16:50:11.000000000 +0300 +++ wget-1.13.4-limitsize/src/main.c 2012-03-27 23:31:24.067650300 +0300 @@ -226,6 +226,7 @@ static struct cmdline_option option_data { "keep-session-cookies", 0, OPT_BOOLEAN, "keepsessioncookies", -1 }, { "level", 'l', OPT_VALUE, "reclevel", -1 }, { "limit-rate", 0, OPT_VALUE, "limitrate", -1 }, + { "limit-size", 0, OPT_VALUE, "limitsize", -1 }, { "load-cookies", 0, OPT_VALUE, "loadcookies", -1 }, { "local-encoding", 0, OPT_VALUE, "localencoding", -1 }, { "max-redirect", 0, OPT_VALUE, "maxredirect", -1 }, @@ -502,6 +503,8 @@ Download:\n"), N_("\ --limit-rate=RATE limit download rate to RATE.\n"), N_("\ + --limit-size=SIZE limit download file size to SIZE.\n"), + N_("\ --no-dns-cache disable caching DNS lookups.\n"), N_("\ --restrict-file-names=OS restrict chars in file names to ones OS allows.\n"), diff -rupN wget-1.13.4.original/src/options.h wget-1.13.4-limitsize/src/options.h --- wget-1.13.4.original/src/options.h 2011-08-06 13:24:32.000000000 +0300 +++ wget-1.13.4-limitsize/src/options.h 2012-03-27 23:33:39.674406600 +0300 @@ -124,6 +124,9 @@ struct options wgint limit_rate; /* Limit the download rate to this many bps. */ + + wgint limit_size; /* Limit the download file size. */ + SUM_SIZE_INT quota; /* Maximum file size to download and store. */