Currently if you use fetch with a ftp directory, you get "File not found." It would be nice if instead this type of query returned a directory listing. Fix: This is a multi-part message in MIME format. --------------050609040308060002090201 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 The attached patch detects a trailing '/' and issues a ftp LIST for directories. New example output: % fetch -vv ftp://ftp.freebsd.org/ scheme: [ftp] user: [] password: [] host: [ftp.freebsd.org] port: [0] document: [/] ---> ftp.freebsd.org:21 looking up ftp.freebsd.org connecting to ftp.freebsd.org:21 <<< 220 Welcome to freebsd.isc.org. >>> USER anonymous <<< 331 Please specify the password. >>> PASS leres@hot.ee.lbl.gov <<< 230 Login successful. >>> PWD <<< 257 "/" >>> MODE S <<< 200 Mode set to S. >>> TYPE I <<< 200 Switching to Binary mode. setting passive mode >>> EPSV <<< 229 Entering Extended Passive Mode (|||38037|). opening data connection initiating transfer >>> LIST <<< 150 Here comes the directory listing. fetch: ftp://ftp.freebsd.org/: size of remote file is not known fetch.out 61 B 902 kBps Waiting for final status <<< 226 Directory send OK. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (FreeBSD) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk1lhtIACgkQWxlAhAje3Ju/awCcDNIQSdUni9QPd2NGdDwdHmfp Xi4An3GOLNEthjToVm9QumxpNrmvwyyP =HwGD -----END PGP SIGNATURE----- --------------050609040308060002090201 Content-Type: text/plain; name="patch-ftp.c" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="patch-ftp.c" --------------050609040308060002090201 Content-Type: application/octet-stream; name="patch-ftp.c.sig" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="patch-ftp.c.sig" iEYEABECAAYFAk1lhtIACgkQWxlAhAje3JuYRQCfSKGOCml2YpxRUt2iexrv9Xlvt2oAnjco uj3cyQco/Q21D2w7JBMq6DGG --------------050609040308060002090201----qb1v91UWzNxEl1YyNwpMKbsOYUyjb1mKIP3mgaQ45TnZ5POZ Content-Type: text/plain; name="file.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="file.diff" --- ftp.c.orig 2011-02-23 14:07:53.000000000 -0800 +++ ftp.c 2011-02-23 14:08:15.000000000 -0800 @@ -777,7 +777,11 @@ /* make the server initiate the transfer */ if (verbose) fetch_info("initiating transfer"); - e = ftp_cmd(conn, "%s %.*s", oper, filenamelen, filename); + if (*filename != '\0') + e = ftp_cmd(conn, "%s %.*s", oper, + filenamelen, filename); + else + e = ftp_cmd(conn, "%s", oper); if (e != FTP_CONNECTION_ALREADY_OPEN && e != FTP_OPEN_DATA_CONNECTION) goto ouch; @@ -868,7 +872,11 @@ /* make the server initiate the transfer */ if (verbose) fetch_info("initiating transfer"); - e = ftp_cmd(conn, "%s %.*s", oper, filenamelen, filename); + if (*filename != '\0') + e = ftp_cmd(conn, "%s %.*s", oper, + filenamelen, filename); + else + e = ftp_cmd(conn, "%s", oper); if (e != FTP_CONNECTION_ALREADY_OPEN && e != FTP_OPEN_DATA_CONNECTION) goto ouch; @@ -1100,6 +1108,7 @@ { conn_t *conn; int oflag; + char *cp; /* check if we should use HTTP instead */ if (purl && strcasecmp(purl->scheme, SCHEME_HTTP) == 0) { @@ -1124,6 +1133,18 @@ if (ftp_cwd(conn, url->doc) == -1) goto errsock; + cp = url->doc + strlen(url->doc) - 1; + if (cp >= url->doc && *cp == '/') { + /* list directory */ + if (us) { + us->size = -1; + us->atime = us->mtime = 0; + } + /* list the directory */ + return ftp_transfer(conn, "LIST", url->doc, O_RDONLY, + url->offset, flags); + } + /* stat file */ if (us && ftp_stat(conn, url->doc, us) == -1 && fetchLastErrCode != FETCH_PROTO How-To-Repeat: % fetch -vv ftp://ftp.freebsd.org/ scheme: [ftp] user: [] password: [] host: [ftp.freebsd.org] port: [0] document: [/] ---> ftp.freebsd.org:21 looking up ftp.freebsd.org connecting to ftp.freebsd.org:21 <<< 220 Welcome to freebsd.isc.org. >>> USER anonymous <<< 331 Please specify the password. >>> PASS leres@hot.ee.lbl.gov <<< 230 Login successful. >>> PWD <<< 257 "/" >>> MODE S <<< 200 Mode set to S. >>> TYPE I <<< 200 Switching to Binary mode. >>> SIZE <<< 550 Could not get file size. >>> MODE S <<< 200 Mode set to S. >>> TYPE I <<< 200 Switching to Binary mode. setting passive mode >>> EPSV <<< 229 Entering Extended Passive Mode (|||11219|). opening data connection initiating transfer >>> RETR <<< 550 Failed to open file. fetch: ftp://ftp.freebsd.org/: File unavailable (e.g., file not found, no access)
Responsible Changed From-To: freebsd-bugs->des des, is this still your area of interest?
batch change: For bugs that match the following - Status Is In progress AND - Untouched since 2018-01-01. AND - Affects Base System OR Documentation DO: Reset to open status. Note: I did a quick pass but if you are getting this email it might be worthwhile to double check to see if this bug ought to be closed.
I am still interested in seeing this feature implemented; I'll upload a current patchset.
Created attachment 193904 [details] revised patch Here's a patch vs. 11.1-RELEASE-p10. I used: fetch -v -o test.txt ftp://ftp.freebsd.org/ for testing.