Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 09 Sep 2000 00:53:23 -0700
From:      Craig Leres <leres@ee.lbl.gov>
To:        FreeBSD-gnats-submit@freebsd.org
Cc:        leres@ee.lbl.gov (Craig Leres)
Subject:   bin/21144: [PATCH] fetch(1): don't bonk if ftp SIZE isn't supproted; add LIST feature
Message-ID:  <200009090753.e897rNT01780@fun.ee.lbl.gov>

next in thread | raw e-mail | index | archive | help

>Number:         21144
>Category:       bin
>Synopsis:       [PATCH] fetch(1): don't bonk if ftp SIZE isn't supproted; 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:   Sat Sep 09 01:00:01 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     Craig Leres
>Release:        FreeBSD 4.1-RELEASE i386
>Organization:
Lawrence Berkeley National Laboratory
>Environment:
>Description:

	If you try to grab a ftp file and the server does not
	support the SIZE command, fetch(1) gets confused and exits.

	The "old" version of fetch could cope with this.

	Also, fetch(1) cannot retreive a ftp directory listing;
	attempts to do so result in a ftp protocol error.

>How-To-Repeat:

	fun 436 % fetch -v ftp://ftp.rs.internic.net/domain/named.root
	looking up ftp.rs.internic.net
	connecting to ftp.rs.internic.net:21
	fetch: named.root: Syntax error, command unrecognized

	[Too bad fetch can't show us the protocol dialogue; that
	would be sweet!]

	fun 433 % ftp ftp.rs.internic.net
	Connected to ftp.rs.internic.net.
	220 rs FTP server (InterNIC Public FTP Server - Login with username anonymous) ready.
	Name (ftp.rs.internic.net:leres): ftp
	331 Guest login ok, send ident as password.
	Password:
	230 Guest login ok, access restrictions apply.
	Remote system type is UNIX.
	Using binary mode to transfer files.
	ftp> cd /domain
	250 CWD command successful.
	ftp> quote SIZE named.root
	500 'SIZE named.root': command not understood.
	ftp> 

	[Here's how the fetch that came with 3.2-RELEASE works;
	note the useful debugging info...]

	ee 66 % uname -r 
	3.2-RELEASE
	ee 67 % fetch ftp://ftp.rs.internic.net/domain/named.root
	fetch: domain/named.root: cannot get remote modification time
	Receiving named.root: 2 Kbytes
	2769 bytes transfered in 0.8 seconds  (3.52 Kbytes/s)
	ee 68 % ,ch,ch -v
	fetch -v ftp://ftp.rs.internic.net/domain/named.root
	Sending: USER anonymous
	rs FTP server (InterNIC Public FTP Server - Login with username anonymous) ready.
	Guest login ok, send ident as password.
	Sending: PASS leres@ee.lbl.gov
	Guest login ok, access restrictions apply.
	Sending: TYPE I
	Type set to I.
	Sending: CWD domain
	CWD command successful.
	Sending SIZE named.root
	'SIZE named.root': command not understood.
	Sending MDTM named.root
	'MDTM named.root': command not understood.
	fetch: domain/named.root: cannot get remote modification time
	Sending: PORT 131,243,1,10,192,18
	PORT command successful.
	Sending: RETR named.root
	Binary data connection for named.root (131.243.1.10,49170) (2769 bytes).
	Receiving named.rootSending: QUIT
	Binary Transfer complete.
	Goodbye.
	Receiving named.root: 2 Kbytes
	2769 bytes transfered in 3.8 seconds  (722 bytes/s)

	[Here's an unsuccessful attempt to get a directory listing]

	fun 450 % fetch -v ftp://ftp.ee.lbl.gov/
	looking up ftp.ee.lbl.gov
	connecting to ftp.ee.lbl.gov:21
	fetch: fetch.out: Syntax error in parameters or arguments

>Fix:

	The appended context diff to lib/libfetch/ftp.c makes these
	changes:

	     - Ignore a syntax/protocol error when fetching a file

	     - Detecting that the filename is empty and do a LIST
	       instead of a RETR

	I submitted a similar patch for the 3.0-RELEASE version of
	fetch:

	    http://www.FreeBSD.org/cgi/query-pr.cgi?pr=9250

	Since the current version of fetch looks like a rewrite,
	you can probbaly close the old report.


===================================================================
RCS file: RCS/ftp.c,v
retrieving revision 1.1
diff -c -r1.1 ftp.c
*** ftp.c	2000/09/08 09:48:25	1.1
--- ftp.c	2000/09/09 07:17:17
***************
*** 451,457 ****
  	/* make the server initiate the transfer */
  	if (verbose)
  	    _fetch_info("initiating transfer");
! 	e = _ftp_cmd(cd, "%s %s", oper, _ftp_filename(file));
  	if (e != FTP_OPEN_DATA_CONNECTION)
  	    goto ouch;
  	
--- 451,460 ----
  	/* make the server initiate the transfer */
  	if (verbose)
  	    _fetch_info("initiating transfer");
! 	if (*_ftp_filename(file) != '\0')
! 		e = _ftp_cmd(cd, "%s %s", oper, _ftp_filename(file));
! 	else
! 		e = _ftp_cmd(cd, "%s", oper);
  	if (e != FTP_OPEN_DATA_CONNECTION)
  	    goto ouch;
  	
***************
*** 541,547 ****
  	/* make the server initiate the transfer */
  	if (verbose)
  	    _fetch_info("initiating transfer");
! 	e = _ftp_cmd(cd, "%s %s", oper, _ftp_filename(file));
  	if (e != FTP_OPEN_DATA_CONNECTION)
  	    goto ouch;
  	
--- 544,553 ----
  	/* make the server initiate the transfer */
  	if (verbose)
  	    _fetch_info("initiating transfer");
! 	if (*_ftp_filename(file) != '\0')
! 		e = _ftp_cmd(cd, "%s %s", oper, _ftp_filename(file));
! 	else
! 		e = _ftp_cmd(cd, "%s", oper);
  	if (e != FTP_OPEN_DATA_CONNECTION)
  	    goto ouch;
  	
***************
*** 782,787 ****
--- 788,794 ----
  fetchXGetFTP(struct url *url, struct url_stat *us, char *flags)
  {
      int cd;
+     register char *cp;
  
      if (_ftp_use_http_proxy())
  	return fetchXGetHTTP(url, us, flags);
***************
*** 793,806 ****
      /* change directory */
      if (_ftp_cwd(cd, url->doc) == -1)
  	return NULL;
      
!     /* stat file */
!     if (us && _ftp_stat(cd, url->doc, us) == -1
! 	&& fetchLastErrCode != FETCH_UNAVAIL)
! 	return NULL;
!     
!     /* initiate the transfer */
!     return _ftp_transfer(cd, "RETR", url->doc, "r", url->offset, flags);
  }
  
  /*
--- 800,824 ----
      /* change directory */
      if (_ftp_cwd(cd, url->doc) == -1)
  	return NULL;
+ 
+     cp = url->doc + strlen(url->doc) - 1;
+     if (cp >= url->doc && *cp == '/') {
+ 	    if (us) {
+ 		    us->size = -1;
+ 		    us->atime = us->mtime = 0;
+ 	    }
+ 	    /* list the directory */
+ 	    return _ftp_transfer(cd, "LIST", url->doc, "r", url->offset, flags);
+     } else {
+ 	    /* stat file */
+ 	    if (us && _ftp_stat(cd, url->doc, us) == -1
+ 		&& fetchLastErrCode != FETCH_UNAVAIL
+ 		&& fetchLastErrCode != FETCH_PROTO)
+ 		return NULL;
      
! 	    /* initiate the transfer */
! 	    return _ftp_transfer(cd, "RETR", url->doc, "r", url->offset, flags);
!     }
  }
  
  /*

>Release-Note:
>Audit-Trail:
>Unformatted:


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200009090753.e897rNT01780>