From: Steven Schubiger Date: Mon, 1 Mar 2010 23:00:17 +0000 (+0100) Subject: Make -i work with FTP. X-Git-Tag: v1.13~195 X-Git-Url: http://sjero.net/git/?p=wget;a=commitdiff_plain;h=ec6950f1a6d29a9f7d732a4d82acc9d43bfaebc4 Make -i work with FTP. --- diff --git a/src/ChangeLog b/src/ChangeLog index be1eea4b..1b8cb04d 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,15 @@ +2010-03-01 Steven Schubiger + + * retr.c (retrieve_url): Retrieve the local filename from ftp_loop. + (retrieve_from_file): Return if there's no input file. + + * ftp.c (ftp_loop_internal): Duplicate the local filename into + retrieve_url's scope when a valid reference is being passed. + (ftp_loop): Call ftp_loop_internal here with passing a + reference to the local filename, elsewhere with NULL. + + * ftp.h: Adjust declaration of ftp_loop. + 2010-01-27 Paul Townsend (tiny change) * retr.c (fd_read_body): Be sure to measure timer when time has diff --git a/src/ftp.c b/src/ftp.c index d141b024..dfe23548 100644 --- a/src/ftp.c +++ b/src/ftp.c @@ -1348,7 +1348,7 @@ Error in server response, closing control connection.\n")); This loop either gets commands from con, or (if ON_YOUR_OWN is set), makes them up to retrieve the file given by the URL. */ static uerr_t -ftp_loop_internal (struct url *u, struct fileinfo *f, ccon *con) +ftp_loop_internal (struct url *u, struct fileinfo *f, ccon *con, char **local_file) { int count, orig_lp; wgint restval, len = 0, qtyread = 0; @@ -1576,6 +1576,10 @@ Removing file due to --delete-after in ftp_loop_internal():\n")); con->cmd |= LEAVE_PENDING; else con->cmd &= ~LEAVE_PENDING; + + if (local_file) + *local_file = xstrdup (locf); + return RETROK; } while (!opt.ntry || (count < opt.ntry)); @@ -1611,7 +1615,7 @@ ftp_get_listing (struct url *u, ccon *con, struct fileinfo **f) con->target = xstrdup (lf); xfree (lf); - err = ftp_loop_internal (u, NULL, con); + err = ftp_loop_internal (u, NULL, con, NULL); lf = xstrdup (con->target); xfree (con->target); con->target = old_target; @@ -1806,7 +1810,7 @@ Already have correct symlink %s -> %s\n\n"), else /* opt.retr_symlinks */ { if (dlthis) - err = ftp_loop_internal (u, f, con); + err = ftp_loop_internal (u, f, con, NULL); } /* opt.retr_symlinks */ break; case FT_DIRECTORY: @@ -1817,7 +1821,7 @@ Already have correct symlink %s -> %s\n\n"), case FT_PLAINFILE: /* Call the retrieve loop. */ if (dlthis) - err = ftp_loop_internal (u, f, con); + err = ftp_loop_internal (u, f, con, NULL); break; case FT_UNKNOWN: logprintf (LOG_NOTQUIET, _("%s: unknown/unsupported file type.\n"), @@ -2096,7 +2100,7 @@ ftp_retrieve_glob (struct url *u, ccon *con, int action) { /* Let's try retrieving it anyway. */ con->st |= ON_YOUR_OWN; - res = ftp_loop_internal (u, NULL, con); + res = ftp_loop_internal (u, NULL, con, NULL); return res; } @@ -2117,7 +2121,8 @@ ftp_retrieve_glob (struct url *u, ccon *con, int action) of URL. Inherently, its capabilities are limited on what can be encoded into a URL. */ uerr_t -ftp_loop (struct url *u, int *dt, struct url *proxy, bool recursive, bool glob) +ftp_loop (struct url *u, char **local_file, int *dt, struct url *proxy, + bool recursive, bool glob) { ccon con; /* FTP connection */ uerr_t res; @@ -2196,7 +2201,7 @@ ftp_loop (struct url *u, int *dt, struct url *proxy, bool recursive, bool glob) ispattern ? GLOB_GLOBALL : GLOB_GETONE); } else - res = ftp_loop_internal (u, NULL, &con); + res = ftp_loop_internal (u, NULL, &con, local_file); } if (res == FTPOK) res = RETROK; diff --git a/src/ftp.h b/src/ftp.h index a93c1371..c0ee354a 100644 --- a/src/ftp.h +++ b/src/ftp.h @@ -120,7 +120,7 @@ enum wget_ftp_fstatus }; struct fileinfo *ftp_parse_ls (const char *, const enum stype); -uerr_t ftp_loop (struct url *, int *, struct url *, bool, bool); +uerr_t ftp_loop (struct url *, char **, int *, struct url *, bool, bool); uerr_t ftp_index (const char *, struct url *, struct fileinfo *); diff --git a/src/retr.c b/src/retr.c index c9cec0fc..ebcc3c20 100644 --- a/src/retr.c +++ b/src/retr.c @@ -700,7 +700,7 @@ retrieve_url (struct url * orig_parsed, const char *origurl, char **file, if (redirection_count) oldrec = glob = false; - result = ftp_loop (u, dt, proxy_url, recursive, glob); + result = ftp_loop (u, &local_file, dt, proxy_url, recursive, glob); recursive = oldrec; /* There is a possibility of having HTTP being redirected to @@ -918,7 +918,9 @@ retrieve_from_file (const char *file, bool html, int *count) status = retrieve_url (url_parsed, url, &input_file, NULL, NULL, &dt, false, iri, true); - if (status != RETROK) + url_free (url_parsed); + + if (!input_file || (status != RETROK)) return status; if (dt & TEXTHTML) diff --git a/tests/ChangeLog b/tests/ChangeLog index 17624f0d..09b0fe58 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,8 @@ +2010-03-01 Steven Schubiger + + * Test-i-ftp.px: Test --input-file in conjunction with FTP. + * run-px, Makefile.am (EXTRA_DIST): Added Test-i-ftp.px. + 2010-02-26 Steven Schubiger * Test-i-http.px: Test --input-file in conjunction with HTTP. diff --git a/tests/Makefile.am b/tests/Makefile.am index e002b321..e83b03a8 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -84,6 +84,7 @@ EXTRA_DIST = FTPServer.pm FTPTest.pm HTTPServer.pm HTTPTest.pm \ Test-HTTP-Content-Disposition-1.px \ Test-HTTP-Content-Disposition-2.px \ Test-HTTP-Content-Disposition.px \ + Test-i-ftp.px \ Test-i-http.px \ Test-idn-headers.px \ Test-idn-meta.px \ diff --git a/tests/Test-i-ftp.px b/tests/Test-i-ftp.px new file mode 100755 index 00000000..1d3bc1ce --- /dev/null +++ b/tests/Test-i-ftp.px @@ -0,0 +1,80 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use FTPTest; + + +############################################################################### + +my $urls = < + + Site 1 + + +

Nunc eu ligula sed mauris sollicitudin scelerisque. Suspendisse viverra, dolor.

+ + +EOF + +my $site2 = < + + Site 2 + + +

Suspendisse potenti. Phasellus et magna est, quis consectetur ligula. Integer.

+ + +EOF + +foreach ($urls, $site1, $site2) { + s/\n/\r\n/g; +} + +my %urls = ( + '/urls.txt' => { + content => $urls, + }, + '/site1.html' => { + content => $site1, + }, + '/site2.html' => { + content => $site2, + }, +); + +my $cmdline = $WgetTest::WGETPATH . " -i ftp://localhost:{{port}}/urls.txt"; + +my $expected_error_code = 0; + +my %expected_downloaded_files = ( + 'urls.txt' => { + content => $urls, + }, + 'site1.html' => { + content => $site1, + }, + 'site2.html' => { + content => $site2, + }, +); + +############################################################################### + +my $the_test = FTPTest->new (name => "Test-i-ftp", + input => \%urls, + cmdline => $cmdline, + errcode => $expected_error_code, + output => \%expected_downloaded_files); +exit $the_test->run(); + +# vim: et ts=4 sw=4 + diff --git a/tests/run-px b/tests/run-px index 6c31dc5e..64dca1a2 100755 --- a/tests/run-px +++ b/tests/run-px @@ -37,6 +37,7 @@ my @tests = ( 'Test-HTTP-Content-Disposition-1.px', 'Test-HTTP-Content-Disposition-2.px', 'Test-HTTP-Content-Disposition.px', + 'Test-i-ftp.px', 'Test-i-http.px', 'Test-idn-headers.px', 'Test-idn-meta.px',