From leres@fun.ee.lbl.gov  Wed Dec 30 16:44:03 1998
Received: from fun.ee.lbl.gov (fun.ee.lbl.gov [131.243.1.81])
          by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id QAA25229
          for <FreeBSD-gnats-submit@freebsd.org>; Wed, 30 Dec 1998 16:44:03 -0800 (PST)
          (envelope-from leres@fun.ee.lbl.gov)
Received: (from leres@localhost)
	by fun.ee.lbl.gov (8.9.1/8.9.1) id QAA03844;
	Wed, 30 Dec 1998 16:43:44 -0800 (PST)
Message-Id: <199812310043.QAA03844@fun.ee.lbl.gov>
Date: Wed, 30 Dec 1998 16:43:44 PST
From: Craig Leres <leres@ee.lbl.gov>
To: FreeBSD-gnats-submit@freebsd.org
Subject: [PATCH] allow fetch to do ftp directory listings
X-Send-Pr-Version: 3.2

>Number:         9250
>Category:       bin
>Synopsis:       [PATCH] allow fetch to do ftp directory listings
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    des
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Dec 30 16:50:01 PST 1998
>Closed-Date:    Thu Sep 28 02:16:20 PDT 2000
>Last-Modified:  Thu Sep 28 02:17:11 PDT 2000
>Originator:     Craig Leres
>Release:        FreeBSD 3.0-RELEASE i386
>Organization:
Lawrence Berkeley National Laboratory
>Environment:

>Description:

	Fetch cannot retreive a ftp directory listing; attempts to
	do so result in a ftp protocol error.

>How-To-Repeat:

	pig 62 % fetch -v ftp://ftp.ee.lbl.gov/
	Sending: USER anonymous
	ee.lbl.gov FTP server ready.
	Guest login ok, send ident as password.
	Sending: PASS leres@pig.ee.lbl.gov
	Guest login ok, access restrictions apply. Your mileage may vary.
	Sending: TYPE I
	Type set to I.
	Sending SIZE 
	'SIZE ': command not understood.
	Sending MDTM 
	'MDTM ': command not understood.
	fetch: : cannot get remote modification time
	Sending: PORT 131,243,1,91,18,188
	PORT command successful.
	Sending: RETR 
	'RETR ': command not understood.
	fetch: ftp://ftp.ee.lbl.gov/: FTP error:
	fetch: Syntax error, command unrecognized
	Sending: QUIT
	Goodbye.

>Fix:
	
	Context diffs to fetch/ftp.c and lib/libftpio.c are appended.
	This is mostly a matter of detecting that the filename is
	empty and doing a LIST instead of a RETR.

	(Note that when doing a directory listing, you should use
	the -o flag.)

RCS file: RCS/ftpio.c,v
retrieving revision 1.1
diff -c -r1.1 ftpio.c
*** /tmp/,RCSt1Wb3719	Wed Dec 30 16:35:42 1998
--- ftpio.c	Thu Dec 17 19:31:40 1998
***************
*** 258,264 ****
      if (ftpBinary(fp) != SUCCESS)
  	return NULL;
  
!     if (ftp_file_op(ftp, "RETR", file, &fp2, "r", seekto) == SUCCESS)
  	return fp2;
      return NULL;
  }
--- 258,265 ----
      if (ftpBinary(fp) != SUCCESS)
  	return NULL;
  
!     if (ftp_file_op(ftp, *file != '\0' ? "RETR" : "LIST", file,
! 	&fp2, "r", seekto) == SUCCESS)
  	return fp2;
      return NULL;
  }
***************
*** 800,806 ****
  		return i;
  	    }
  	}
! 	i = cmd(ftp, "%s %s", operation, file);
  	if (i < 0 || i > 299) {
  	    close(s);
  	    ftp->error = i;
--- 801,810 ----
  		return i;
  	    }
  	}
! 	if (*file != '\0')
! 		i = cmd(ftp, "%s %s", operation, file);
! 	else
! 		i = cmd(ftp, "%s", operation);
  	if (i < 0 || i > 299) {
  	    close(s);
  	    ftp->error = i;
***************
*** 846,852 ****
  	    else if (i != 350)
  		*seekto = (off_t)0;
  	}
! 	i = cmd(ftp, "%s %s", operation, file);
  	if (i < 0 || i > 299) {
  	    close(s);
  	    ftp->error = i;
--- 850,859 ----
  	    else if (i != 350)
  		*seekto = (off_t)0;
  	}
! 	if (*file != '\0')
! 		i = cmd(ftp, "%s %s", operation, file);
! 	else
! 		i = cmd(ftp, "%s", operation);
  	if (i < 0 || i > 299) {
  	    close(s);
  	    ftp->error = i;

RCS file: RCS/ftp.c,v
retrieving revision 1.1
diff -c -r1.1 ftp.c
*** /tmp/,RCSt1gg3685	Wed Dec 30 16:35:15 1998
--- ftp.c	Thu Dec 17 19:35:44 1998
***************
*** 382,392 ****
  		      (unsigned long)size);
  		return EX_DATAERR;
  	}
! 	modtime = ftpGetModtime(ftp, ftps->ftp_remote_file);
! 	if (modtime <= 0) {	/* xxx */
! 		warnx("%s: cannot get remote modification time", 
! 		      ftps->ftp_remote_path);
  		modtime = -1;
  	}
  	fs->fs_modtime = modtime;
  	seekloc = wehave = 0;
--- 382,396 ----
  		      (unsigned long)size);
  		return EX_DATAERR;
  	}
! 	if (*ftps->ftp_remote_file == '\0')
  		modtime = -1;
+ 	else {
+ 		modtime = ftpGetModtime(ftp, ftps->ftp_remote_file);
+ 		if (modtime <= 0) {	/* xxx */
+ 			warnx("%s: cannot get remote modification time", 
+ 			      ftps->ftp_remote_path);
+ 			modtime = -1;
+ 		}
  	}
  	fs->fs_modtime = modtime;
  	seekloc = wehave = 0;
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->des 
Responsible-Changed-By: des 
Responsible-Changed-When: Thu Jun 29 03:37:31 PDT 2000 
Responsible-Changed-Why:  
fetch(1) is mine. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=9250 
State-Changed-From-To: open->closed 
State-Changed-By: des 
State-Changed-When: Thu Sep 28 02:16:20 PDT 2000 
State-Changed-Why:  
Closed at originator's request. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=9250 
>Unformatted:
