X-Git-Url: http://sjero.net/git/?p=wget;a=blobdiff_plain;f=src%2Fftp.c;h=fed0597c319d5575c04dab6cbdd8f0e6fb416e13;hp=9a77fc108bbd76bcd6ed5229830f6ff033b5fedb;hb=e911bc29434b7da90446d2ca5304106724d05680;hpb=0967c21094580317353f0742c4836c5bbea34059 diff --git a/src/ftp.c b/src/ftp.c index 9a77fc10..fed0597c 100644 --- a/src/ftp.c +++ b/src/ftp.c @@ -32,15 +32,10 @@ so, delete this exception statement from your version. */ #include #include -#ifdef HAVE_STRING_H -# include -#else -# include -#endif +#include #ifdef HAVE_UNISTD_H # include #endif -#include #include #include @@ -55,10 +50,6 @@ so, delete this exception statement from your version. */ #include "convert.h" /* for downloaded_file */ #include "recur.h" /* for INFINITE_RECURSION */ -#ifndef errno -extern int errno; -#endif - extern LARGE_INT total_downloaded_bytes; /* File where the "ls -al" listing will be saved. */ @@ -236,8 +227,7 @@ print_length (wgint size, wgint start, int authoritative) logprintf (LOG_VERBOSE, _(", %s remaining"), with_thousand_seps (size - start)); } - if (!authoritative) - logputs (LOG_VERBOSE, _(" (unauthoritative)\n")); + logputs (LOG_VERBOSE, !authoritative ? _(" (unauthoritative)\n") : "\n"); } /* Retrieves a file with denoted parameters through opening an FTP @@ -628,7 +618,7 @@ Error in server response, closing control connection.\n")); /* If anything is to be retrieved, PORT (or PASV) must be sent. */ if (cmd & (DO_LIST | DO_RETR)) { - if (opt.ftp_pasv > 0) + if (opt.ftp_pasv) { ip_address passive_addr; int passive_port; @@ -1112,7 +1102,7 @@ ftp_loop_internal (struct url *u, struct fileinfo *f, ccon *con) if (opt.noclobber && file_exists_p (con->target)) { logprintf (LOG_VERBOSE, - _("File `%s' already there, not retrieving.\n"), con->target); + _("File `%s' already there; not retrieving.\n"), con->target); /* If the file is there, we suppose it's retrieved OK. */ return RETROK; } @@ -1159,13 +1149,17 @@ ftp_loop_internal (struct url *u, struct fileinfo *f, ccon *con) } /* Decide whether or not to restart. */ - restval = 0; - if (count > 1) - restval = len; /* start where the previous run left off */ - else if (opt.always_rest - && stat (locf, &st) == 0 - && S_ISREG (st.st_mode)) + if (opt.always_rest + && stat (locf, &st) == 0 + && S_ISREG (st.st_mode)) + /* When -c is used, continue from on-disk size. (Can't use + hstat.len even if count>1 because we don't want a failed + first attempt to clobber existing data.) */ restval = st.st_size; + else if (count > 1) + restval = len; /* start where the previous run left off */ + else + restval = 0; /* Get the current time string. */ tms = time_str (NULL); @@ -1352,12 +1346,10 @@ ftp_get_listing (struct url *u, ccon *con, struct fileinfo **f) return err; } -static uerr_t ftp_retrieve_dirs PARAMS ((struct url *, struct fileinfo *, - ccon *)); -static uerr_t ftp_retrieve_glob PARAMS ((struct url *, ccon *, int)); -static struct fileinfo *delelement PARAMS ((struct fileinfo *, - struct fileinfo **)); -static void freefileinfo PARAMS ((struct fileinfo *f)); +static uerr_t ftp_retrieve_dirs (struct url *, struct fileinfo *, ccon *); +static uerr_t ftp_retrieve_glob (struct url *, ccon *, int); +static struct fileinfo *delelement (struct fileinfo *, struct fileinfo **); +static void freefileinfo (struct fileinfo *f); /* Retrieve a list of files given in struct fileinfo linked list. If a file is a symbolic link, do not retrieve it, but rather try to @@ -1850,15 +1842,25 @@ ftp_loop (struct url *u, int *dt, struct url *proxy) } else { - int wild = has_wildcards_p (u->file); - if ((opt.ftp_glob && wild) || opt.recursive || opt.timestamping) + int ispattern = 0; + if (opt.ftp_glob) + { + /* Treat the URL as a pattern if the file name part of the + URL path contains wildcards. (Don't check for u->file + because it is unescaped and therefore doesn't leave users + the option to escape literal '*' as %2A.) */ + char *file_part = strrchr (u->path, '/'); + if (!file_part) + file_part = u->path; + ispattern = has_wildcards_p (file_part); + } + if (ispattern || opt.recursive || opt.timestamping) { /* ftp_retrieve_glob is a catch-all function that gets called if we need globbing, time-stamping or recursion. Its third argument is just what we really need. */ res = ftp_retrieve_glob (u, &con, - (opt.ftp_glob && wild) - ? GLOB_GLOBALL : GLOB_GETONE); + ispattern ? GLOB_GLOBALL : GLOB_GETONE); } else res = ftp_loop_internal (u, NULL, &con);