diff -ru old/wget-1.9.1/src/ftp.c wget-1.9.1/src/ftp.c --- old/wget-1.9.1/src/ftp.c 2003-10-15 01:52:12.000000000 +0300 +++ wget-1.9.1/src/ftp.c 2004-10-21 06:51:14.000000000 +0300 @@ -840,6 +840,10 @@ expected_bytes = *len; } + if (opt.limitbytes + && (!expected_bytes || expected_bytes > opt.limitbytes)) + expected_bytes = opt.limitbytes; + /* If no transmission was required, then everything is OK. */ if (!pasv_mode_open) /* we are not using pasive mode so we need to accept */ @@ -893,15 +897,7 @@ } } - if (*len) - { - logprintf (LOG_VERBOSE, _("Length: %s"), legible (*len)); - if (restval) - logprintf (LOG_VERBOSE, _(" [%s to go]"), legible (*len - restval)); - logputs (LOG_VERBOSE, "\n"); - expected_bytes = *len; /* for get_contents/show_progress */ - } - else if (expected_bytes) + if (expected_bytes) { logprintf (LOG_VERBOSE, _("Length: %s"), legible (expected_bytes)); if (restval) @@ -909,10 +905,18 @@ legible (expected_bytes - restval)); logputs (LOG_VERBOSE, _(" (unauthoritative)\n")); } + else if (*len) + { + logprintf (LOG_VERBOSE, _("Length: %s"), legible (*len)); + if (restval) + logprintf (LOG_VERBOSE, _(" [%s to go]"), legible (*len - restval)); + logputs (LOG_VERBOSE, "\n"); + expected_bytes = *len; /* for get_contents/show_progress */ + } /* Get the contents of the document. */ res = get_contents (dtsock, fp, len, restval, expected_bytes, &con->rbuf, - 0, &con->dltime); + opt.limitbytes, &con->dltime); tms = time_str (NULL); tmrate = retr_rate (*len - restval, con->dltime, 0); /* Close data connection socket. */ @@ -965,6 +969,8 @@ ftp_loop_internal to decide). */ CLOSE (csock); rbuf_uninitialize (&con->rbuf); + if (res > 0) + return RETRFINISHED; return FTPRETRINT; } /* err != FTPOK */ /* If retrieval failed for any reason, return FTPRETRINT, but do not @@ -974,6 +980,8 @@ if (*respline != '2') { xfree (respline); + if (res > 0) + return RETRFINISHED; if (res != -1) logprintf (LOG_NOTQUIET, "%s (%s) - ", tms, tmrate); logputs (LOG_NOTQUIET, _("Data transfer aborted.\n")); @@ -1088,12 +1096,12 @@ } /* Assume no restarting. */ - restval = 0L; + restval = opt.skipbytes; if ((count > 1 || opt.always_rest) && !(con->cmd & DO_LIST) && file_exists_p (locf)) if (stat (locf, &st) == 0 && S_ISREG (st.st_mode)) - restval = st.st_size; + restval = opt.skipbytes + st.st_size; /* In `-c' is used, check whether the file we're writing to exists and is of non-zero length. If so, we'll refuse to diff -ru old/wget-1.9.1/src/http.c wget-1.9.1/src/http.c --- old/wget-1.9.1/src/http.c 2003-10-15 02:32:15.000000000 +0300 +++ wget-1.9.1/src/http.c 2004-10-21 06:49:20.000000000 +0300 @@ -799,9 +799,9 @@ else pragma_h = ""; - if (hs->restval) + if (hs->restval || opt.limitbytes) { - range = (char *)alloca (13 + numdigit (hs->restval) + 4); + range = (char *)alloca (13 + numdigit (hs->restval) + 1 + numdigit (opt.limitbytes) + 4); /* Gag me! Some servers (e.g. WebSitePro) have been known to respond to the following `Range' format by generating a multipart/x-byte-ranges MIME document! This MIME type was @@ -809,7 +809,15 @@ HTTP/1.1 specifies a multipart/byte-ranges MIME type, but only if multiple non-overlapping ranges are requested -- which Wget never does. */ - sprintf (range, "Range: bytes=%ld-\r\n", hs->restval); + if (hs->restval) + { + if (opt.limitbytes) + sprintf (range, "Range: bytes=%ld-%d\r\n", hs->restval, opt.limitbytes-1); + else + sprintf (range, "Range: bytes=%ld-\r\n", hs->restval); + } + else + sprintf (range, "Range: bytes=-%d\r\n", opt.limitbytes-1); } else range = NULL; @@ -1428,7 +1436,9 @@ if (hs->restval) { - if (contlen != -1) + if (opt.limitbytes && opt.limitbytes > contrange) + contlen = opt.limitbytes; + else if (contlen != -1) contlen += contrange; else contrange = -1; /* If conent-length was not sent, @@ -1533,7 +1543,7 @@ /* Get the contents of the document. */ hs->res = get_contents (sock, fp, &hs->len, hs->restval, (contlen != -1 ? contlen : 0), - &rbuf, keep_alive, &hs->dltime); + &rbuf, keep_alive || opt.limitbytes, &hs->dltime); if (hs->res >= 0) CLOSE_FINISH (sock); @@ -1732,7 +1742,7 @@ else *dt &= ~HEAD_ONLY; /* Assume no restarting. */ - hstat.restval = 0L; + hstat.restval = opt.skipbytes; /* Decide whether or not to restart. */ if (((count > 1 && (*dt & ACCEPTRANGES)) || opt.always_rest) /* #### this calls access() and then stat(); could be optimized. */ diff -ru old/wget-1.9.1/src/init.c wget-1.9.1/src/init.c --- old/wget-1.9.1/src/init.c 2003-10-11 16:57:11.000000000 +0300 +++ wget-1.9.1/src/init.c 2004-10-21 05:45:04.000000000 +0300 @@ -165,6 +165,7 @@ { "includedirectories", &opt.includes, cmd_directory_vector }, { "input", &opt.input_filename, cmd_file }, { "killlonger", &opt.kill_longer, cmd_boolean }, + { "limitbytes", &opt.limitbytes, cmd_number }, { "limitrate", &opt.limit_rate, cmd_bytes }, { "loadcookies", &opt.cookies_input, cmd_file }, { "logfile", &opt.lfilename, cmd_file }, @@ -201,6 +202,7 @@ { "savecookies", &opt.cookies_output, cmd_file }, { "saveheaders", &opt.save_headers, cmd_boolean }, { "serverresponse", &opt.server_response, cmd_boolean }, + { "skipbytes", &opt.skipbytes, cmd_number }, { "spanhosts", &opt.spanhost, cmd_boolean }, { "spider", &opt.spider, cmd_boolean }, #ifdef HAVE_SSL diff -ru old/wget-1.9.1/src/main.c wget-1.9.1/src/main.c --- old/wget-1.9.1/src/main.c 2003-10-11 16:57:11.000000000 +0300 +++ wget-1.9.1/src/main.c 2004-10-21 06:24:27.000000000 +0300 @@ -186,6 +186,11 @@ --restrict-file-names=OS restrict chars in file names to ones OS allows.\n\ \n"), stdout); fputs (_("\ +Ranges:\n\ + --skip-bytes=offset retrieve file starting from offset\n\ + --limit-bytes=offset retrieve file up to byte offset\n\ +\n"), stdout); + fputs (_("\ Directories:\n\ -nd, --no-directories don\'t create directories.\n\ -x, --force-directories force creation of directories.\n\ @@ -373,6 +378,8 @@ #endif /* HAVE_SSL */ { "wait", required_argument, NULL, 'w' }, { "waitretry", required_argument, NULL, 152 }, + { "skip-bytes", required_argument, NULL, 181 }, + { "limit-bytes", required_argument, NULL, 182 }, { 0, 0, 0, 0 } }; @@ -636,6 +643,12 @@ case 180: setoptval ("connecttimeout", optarg); break; + case 181: + setoptval ("skipbytes", optarg); + break; + case 182: + setoptval ("limitbytes", optarg); + break; case 'A': setoptval ("accept", optarg); break; diff -ru old/wget-1.9.1/src/options.h wget-1.9.1/src/options.h --- old/wget-1.9.1/src/options.h 2003-10-11 16:57:11.000000000 +0300 +++ wget-1.9.1/src/options.h 2004-10-21 05:47:40.000000000 +0300 @@ -194,6 +194,8 @@ int strict_comments; /* whether strict SGML comments are enforced. */ + int skipbytes; + int limitbytes; }; extern struct options opt;