bin/154988: [PATCH] lib/libfetch/ftp.c add LIST feature
Craig Leres
leres at ee.lbl.gov
Wed Feb 23 22:20:06 UTC 2011
>Number: 154988
>Category: bin
>Synopsis: [PATCH] lib/libfetch/ftp.c add LIST feature
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Wed Feb 23 22:20:05 UTC 2011
>Closed-Date:
>Last-Modified:
>Originator: Craig Leres
>Release: FreeBSD 8.2-RELEASE amd64
>Organization:
Lawrence Berkeley National Laboratory
>Environment:
FreeBSD hot.ee.lbl.gov 8.2-RELEASE FreeBSD 8.2-RELEASE #0 r8: Tue Feb
22 19:50:59 PST 2011
leres at hot.ee.lbl.gov:/usr/src/8.2-RELEASE/sys/amd64/compile/LBLSMPIPV6
amd64
>Description:
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.
>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 at 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)
>Fix:
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 at 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"
--- 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
--------------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--
>Release-Note:
>Audit-Trail:
>Unformatted:
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
More information about the freebsd-bugs
mailing list