From obrien@dragon.nuxi.com  Wed Oct  1 04:22:28 1997
Received: from kongur.cs.ucdavis.edu (kongur.cs.ucdavis.edu [128.120.56.192])
          by hub.freebsd.org (8.8.7/8.8.7) with ESMTP id EAA07137
          for <FreeBSD-gnats-submit@freebsd.org>; Wed, 1 Oct 1997 04:22:25 -0700 (PDT)
Received: from dragon.nuxi.com (d60-072.leach.ucdavis.edu [169.237.60.72])
	by kongur.cs.ucdavis.edu (8.8.5/8.8.5) with ESMTP id EAA21764
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 1 Oct 1997 04:21:12 -0700 (PDT)
Received: (from obrien@localhost) by dragon.nuxi.com (8.8.7/8.7.3) id LAA14939; Wed, 1 Oct 1997 11:21:12 GMT
Message-Id: <19971001042111.56343@dragon.nuxi.com>
Date: Wed, 1 Oct 1997 04:21:11 -0700
From: "David O'Brien" <obrien@NUXI.COM>
Reply-To: obrien@NUXI.COM
To: FreeBSD-gnats-submit@freebsd.org
Subject: /usr/bin/fetch fails to ftp a file ncftp can
X-Send-Pr-Version: 3.2

>Number:         4670
>Category:       bin
>Synopsis:       /usr/bin/fetch fails to ftp a file ncftp can
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:
>Keywords:
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Oct  1 04:30:01 PDT 1997
>Closed-Date:    Sun Oct 5 18:10:32 PDT 1997
>Last-Modified:  Sun Oct  5 18:11:29 PDT 1997
>Originator:     David O'Brien
>Release:        FreeBSD 2.2-STABLE i386
>Organization:
The FreeBSD Project
>Environment:

    2.2-STABLE built sept-03
   
>Description:

    fetch ftp://ftp.fu-berlin.de/pub/unix/mail/mutt/mutt-pgp/mutt-0.84e-0.84.dif
    fails, where as
    ncftp ftp://ftp.fu-berlin.de/pub/unix/mail/mutt/mutt-pgp/mutt-0.84e-0.84.dif
    works

    bash$ fetch -v ftp://ftp.fu-berlin.de/pub/unix/mail/mutt/mutt-pgp/mutt-0.84e
    Sending: USER anonymous
    FTP.FU-Berlin.DE ready, please login as user "ftp".
    Anonymous login ok, send your e-mail address as password.
    Sending: PASS obrien@dragon.nuxi.com
   
    Welcome at Freie Universitaet Berlin, Germany.
   
    Anonymous login ok, for special commands see the README.
    Sending: TYPE I
    Type set to I.
    Sending SIZE pub/unix/mail/mutt/mutt-pgp/mutt-0.84e-0.84.diff.gz
    pub/unix/mail/mutt/mutt-pgp/mutt-0.84e-0.84.diff.gz: not a plain file.
    Sending MDTM pub/unix/mail/mutt/mutt-pgp/mutt-0.84e-0.84.diff.gz
    pub/unix/mail/mutt/mutt-pgp/mutt-0.84e-0.84.diff.gz: No such file or directo
    fetch: pub/unix/mail/mutt/mutt-pgp/mutt-0.84e-0.84.diff.gz: cannot get remot
    Sending: PORT 169,237,60,72,4,246
    PORT command successful.
    Sending: RETR pub/unix/mail/mutt/mutt-pgp/mutt-0.84e-0.84.diff.gz
    pub/unix/mail/mutt/mutt-pgp/mutt-0.84e-0.84.diff.gz: No such file OR directo
    fetch: ftp://ftp.fu-berlin.de/pub/unix/mail/mutt/mutt-pgp/mutt-0.84e-0.84.di
    fetch: File unavailable (e.g., file not found, no access)
    Sending: QUIT 
    Goodbye.
    bash$
    bash$
    bash$ ncftp ftp://ftp.fu-berlin.de/pub/unix/mail/mutt/mutt-pgp/mutt-0.84e-0.
    FTP.FU-Berlin.DE ready, please login as user "ftp".
    Receiving file: mutt-0.84e-0.84.diff.gz
    mutt-0.84e-0.84.diff.gz: 13751 bytes received in 11.27 seconds, 1.19 K/s.
    exit
    
    
>How-To-Repeat:
    
    fetch ftp://ftp.fu-berlin.de/pub/unix/mail/mutt/mutt-pgp/mutt-0.84e-0.84.dif
    ncftp ftp://ftp.fu-berlin.de/pub/unix/mail/mutt/mutt-pgp/mutt-0.84e-0.84.dif


>Fix:
	
	???
>Release-Note:
>Audit-Trail:

From: John-Mark Gurney <gurney_j@efn.org>
To: obrien@NUXI.COM
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: bin/4670: /usr/bin/fetch fails to ftp a file ncftp can
Date: Wed, 1 Oct 1997 10:46:51 -0700

 David O'Brien scribbled this message on Oct 1:
 >     Sending SIZE pub/unix/mail/mutt/mutt-pgp/mutt-0.84e-0.84.diff.gz
 >     pub/unix/mail/mutt/mutt-pgp/mutt-0.84e-0.84.diff.gz: not a plain file.
 >     Sending MDTM pub/unix/mail/mutt/mutt-pgp/mutt-0.84e-0.84.diff.gz
 >     pub/unix/mail/mutt/mutt-pgp/mutt-0.84e-0.84.diff.gz: No such file or directo
 >     fetch: pub/unix/mail/mutt/mutt-pgp/mutt-0.84e-0.84.diff.gz: cannot get remot
 >     Sending: PORT 169,237,60,72,4,246
 >     PORT command successful.
 >     Sending: RETR pub/unix/mail/mutt/mutt-pgp/mutt-0.84e-0.84.diff.gz
 >     pub/unix/mail/mutt/mutt-pgp/mutt-0.84e-0.84.diff.gz: No such file OR directo
 >     fetch: ftp://ftp.fu-berlin.de/pub/unix/mail/mutt/mutt-pgp/mutt-0.84e-0.84.di
 >     fetch: File unavailable (e.g., file not found, no access)
 >     Sending: QUIT 
 >     Goodbye.
 >     bash$
 >     bash$
 >     bash$ ncftp ftp://ftp.fu-berlin.de/pub/unix/mail/mutt/mutt-pgp/mutt-0.84e-0.
 >     FTP.FU-Berlin.DE ready, please login as user "ftp".
 >     Receiving file: mutt-0.84e-0.84.diff.gz
 >     mutt-0.84e-0.84.diff.gz: 13751 bytes received in 11.27 seconds, 1.19 K/s.
 >     exit
 
 well.. basicly the output tells you all you need.. when you login,
 the file pub/unix/mail/.../mutt isn't avail.. it turns out that the
 ftp server decides to dump you in the /pub directory instead of the
 root directory...  so you end up duplicating the pub...
 
 now the question is, should we simply add a / to the front of the path
 in fetch?  it would fix it...  I don't have my RFC database close at hand
 but does it tell you whwer you are suppose to get dumped when you login?
 
 -- 
   John-Mark Gurney                          Modem/FAX: +1 541 683 6954
   Cu Networking
 
   Live in Peace, destroy Micro$oft, support free software, run FreeBSD

From: Bill Fenner <fenner@parc.xerox.com>
To: Garrett Wollman <wollman@khavrinen.lcs.mit.edu>
Cc: freebsd-gnats-submit@freebsd.org
Subject: Re: bin/4670: /usr/bin/fetch fails to ftp a file ncftp can 
Date: Wed, 1 Oct 1997 12:41:51 PDT

 However, if fetch followed the RFC1738 definition of ftp: URL's, then it
 would be able to fetch this particular URL.
 
 Sending: USER anonymous
 FTP.FU-Berlin.DE ready, please login as user "ftp".
 Anonymous login ok, send your e-mail address as password.
 Sending: PASS fenner@ampere.freebsd.org
 
 Welcome at Freie Universitaet Berlin, Germany.
 
 Anonymous login ok, for special commands see the README.
 Sending: TYPE I
 Type set to I.
 Sending: CWD pub
 CWD command successful.
 Sending: CWD unix
 CWD command successful.
 Sending: CWD mail
 CWD command successful.
 Sending: CWD mutt
 CWD command successful.
 Sending: CWD mutt-pgp
 This is the Mutt version with PGP support.  I always try to upload the
 latest version here.  This is either the illegally exported version from
   ftp://ftp.teuto.de/pub/user/lmb
 or my adaption of the PGP parts to a newer Mutt version.  This is an
 inofficial Mutt version.
                                 leitner@math.fu-berlin.de
 
 CWD command successful.
 Sending SIZE mutt-0.84e-0.84.diff.gz
 13751
 Sending MDTM mutt-0.84e-0.84.diff.gz
 19970917125011
 Sending: PORT 204,216,27,20,4,19
 PORT command successful.
 Sending: RETR mutt-0.84e-0.84.diff.gz
 Opening BINARY mode data connection for mutt-0.84e-0.84.diff.gz (13751 bytes).
 Receiving mutt-0.84e-0.84.diff.gz (13751 bytes)Sending: QUIT
 Transfer complete.
 
 
 The following diff causes fetch to interpret FTP URL's as RFC1738
 defines.
 
   Bill
 
 Index: ftp.c
 ===================================================================
 RCS file: /home/ncvs/src/usr.bin/fetch/ftp.c,v
 retrieving revision 1.7
 diff -u -r1.7 ftp.c
 --- ftp.c	1997/05/31 14:45:41	1.7
 +++ ftp.c	1997/10/01 19:33:41
 @@ -293,6 +293,7 @@
  	off_t seekloc, wehave;
  	time_t modtime;
  	size_t readresult, writeresult;
 +	char *p, *q, *path;
  
  	ftp = ftpLogin(ftps->ftp_hostname, 
  		       (char *)(ftps->ftp_user ? ftps->ftp_user : "anonymous"),
 @@ -306,8 +307,19 @@
  	}
  	ftpBinary(ftp);
  	ftpPassive(ftp, fs->fs_passive_mode);
 -	size = ftpGetSize(ftp, ftps->ftp_remote_file);
 -	modtime = ftpGetModtime(ftp, ftps->ftp_remote_file);
 +	p = path = safe_strdup(ftps->ftp_remote_file);
 +	while ((q = strchr(p, '/')) != 0) {
 +		*q++ = '\0';
 +		if ((status = ftpChdir(ftp, p)) != 0) {
 +			warnx("%s: %s: %s", ftps->ftp_hostname,
 +				p, ftpErrString(status));
 +			free(path);
 +			return EX_IOERR;
 +		}
 +		p = q;
 +	}
 +	size = ftpGetSize(ftp, p);
 +	modtime = ftpGetModtime(ftp, p);
  	if (modtime <= 0) {	/* xxx */
  		warnx("%s: cannot get remote modification time", 
  		      ftps->ftp_remote_file);
 @@ -334,6 +346,7 @@
  		if (fs->fs_mirror && stab.st_size == size
  		    && modtime <= stab.st_mtime) {
  			fclose(ftp);
 +			free(path);
  			return 0;
  		}
  		if (fs->fs_restart) {
 @@ -342,7 +355,8 @@
  		}
  	}
  
 -	remote = ftpGet(ftp, ftps->ftp_remote_file, &seekloc);
 +	remote = ftpGet(ftp, p, &seekloc);
 +	free(path);
  	if (remote == 0) {
  		if (ftpErrno(ftp)) {
  			warnx("ftp://%s/%s: FTP error:",

From: Bill Fenner <fenner@parc.xerox.com>
To: freebsd-gnats-submit@freebsd.org
Cc:  Subject: Re: bin/4670: /usr/bin/fetch fails to ftp a file ncftp can 
Date: Wed, 1 Oct 1997 13:07:36 PDT

 Oops; that patch doesn't handle encoded slashes right.  Looks like
 ftp_parse() has to break up the elements of the path and call
 percent_decode() on each element individually, and save the list
 in ftps for ftp_retrieve() to use.
 
   Bill

From: "David O'Brien" <obrien@NUXI.COM>
To: John-Mark Gurney <gurney_j@resnet.uoregon.edu>
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: bin/4670: /usr/bin/fetch fails to ftp a file ncftp can
Date: Sun, 5 Oct 1997 14:13:55 -0700

 > well.. basicly the output tells you all you need.. when you login,
 > the file pub/unix/mail/.../mutt isn't avail.. it turns out that the
 > ftp server decides to dump you in the /pub directory instead of the
 > root directory...  so you end up duplicating the pub...
 > 
 > now the question is, should we simply add a / to the front of the path
 > in fetch?  it would fix it...  
 
 I'd say yes.  It is the implimentation of least surprize.  If I wanted a
 relative path, I'd have specified it as:
 
     ftp://ftp.foo.com/./some/dir/path/filewanted.tar.gz
 
 
 -- 
 -- David	(obrien@NUXI.com  -or-  obrien@FreeBSD.org)
State-Changed-From-To: open->closed 
State-Changed-By: fenner 
State-Changed-When: Sun Oct 5 18:10:32 PDT 1997 
State-Changed-Why:  
Fixed in rev 1.8 of ftp.c; fetch now uses the proper RFC1738 
interpretation of ftp URL's which allows this URL to be fetched. 
>Unformatted:
