From d34270c536e3af009031c4fffd3d9a8c8440dbe8 Mon Sep 17 00:00:00 2001 From: mtortonesi Date: Thu, 9 Mar 2006 05:50:03 -0800 Subject: [PATCH] [svn] Add support for download of hidden files from FTP. --- src/ChangeLog | 5 ++++ src/ftp-basic.c | 64 +++++++++++++++++++++++++++++-------------------- 2 files changed, 43 insertions(+), 26 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 35df0375..04fea0d5 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2006-03-09 Mauro Tortonesi + + * ftp.c (ftp_list): Try `LIST -a' command first and revert to `LIST' + in case of failure. + 2006-03-06 Hrvoje Niksic * hash.c (TOLOWER): Fix definition when STANDALONE. diff --git a/src/ftp-basic.c b/src/ftp-basic.c index dd7d7b7a..4127b686 100644 --- a/src/ftp-basic.c +++ b/src/ftp-basic.c @@ -962,33 +962,45 @@ ftp_list (int csock, const char *file) char *request, *respline; int nwritten; uerr_t err; + bool ok = false; + int i = 0; + /* Try `LIST -a' first and revert to `LIST' in case of failure. */ + const char *list_commands[] = { "LIST -a", + "LIST" }; - /* Send LIST request. */ - request = ftp_request ("LIST", file); - nwritten = fd_write (csock, request, strlen (request), -1); - if (nwritten < 0) - { - xfree (request); - return WRITEFAILED; - } - xfree (request); - /* Get appropriate respone. */ - err = ftp_response (csock, &respline); - if (err != FTPOK) - return err; - if (*respline == '5') - { - xfree (respline); - return FTPNSFOD; - } - if (*respline != '1') - { - xfree (respline); - return FTPRERR; - } - xfree (respline); - /* All OK. */ - return FTPOK; + do { + /* Send request. */ + request = ftp_request (list_commands[i], file); + nwritten = fd_write (csock, request, strlen (request), -1); + if (nwritten < 0) + { + xfree (request); + return WRITEFAILED; + } + xfree (request); + /* Get appropriate response. */ + err = ftp_response (csock, &respline); + if (err == FTPOK) + { + if (*respline == '5') + { + err = FTPNSFOD; + } + else if (*respline == '1') + { + err = FTPOK; + ok = true; + } + else + { + err = FTPRERR; + } + xfree (respline); + } + ++i; + } while (i < countof (list_commands) && !ok); + + return err; } /* Sends the SYST command to the server. */