wu-ftpd and possibly other FTP servers don't like closing the data
connection after a RETR without an ABOR.

To witness:

  $ HEAD ftp://ftp.wu-ftpd.org/pub/README
  500 Timeout
  Client-Date: Sun, 15 Jun 2003 17:28:47 GMT

According to RFC 959 (4.1.3), ABOR after a successful transfer should be
non-intrusive.  Additionally, Net::FTP::dataconn does a close (only)
anyway if the transfer was already completed.  Fix attached, which also
makes the HEAD response code special case obsolete.  After applying it:

  $ HEAD ftp://ftp.wu-ftpd.org/pub/README
  200 OK
  Server: ftp.wu-ftpd.org FTP server
  Content-Length: 1277
  Content-Type: application/octet-stream
  Last-Modified: Tue, 11 Dec 2001 17:11:46 GMT
  Client-Date: Sun, 15 Jun 2003 17:33:12 GMT
  Client-Request-Num: 1

-- 
\/ille Skytt�
ville.skytta at iki.fi

Index: lib/LWP/Protocol/ftp.pm
===================================================================
RCS file: /cvsroot/libwww-perl/lwp5/lib/LWP/Protocol/ftp.pm,v
retrieving revision 1.31
diff -a -u -r1.31 ftp.pm
--- lib/LWP/Protocol/ftp.pm	26 Oct 2001 20:13:20 -0000	1.31
+++ lib/LWP/Protocol/ftp.pm	15 Jun 2003 17:42:40 -0000
@@ -315,13 +315,13 @@
 		    return \$content;
 		} );
 	    }
-	    unless ($data->close) {
+	    # abort is needed for HEAD, and it's == close if the transfer has
+	    # already completed.
+	    unless ($data->abort) {
 		# Something did not work too well
-		if ($method ne 'HEAD') {
-		    $response->code(&HTTP::Status::RC_INTERNAL_SERVER_ERROR);
-		    $response->message("FTP close response: " . $ftp->code .
-				       " " . $ftp->message);
-		}
+		$response->code(&HTTP::Status::RC_INTERNAL_SERVER_ERROR);
+		$response->message("FTP close response: " . $ftp->code .
+				   " " . $ftp->message);
 	    }
 	} elsif (!length($remote_file) || $ftp->code == 550) {
 	    # 550 not a plain file, try to list instead

Reply via email to