Bug 10747 - ftp SIZE command and 'smart' ftp servers results in wrong Content-Length value
Summary: ftp SIZE command and 'smart' ftp servers results in wrong Content-Length value
Status: NEW
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: mod_proxy_http (show other bugs)
Version: 2.5-HEAD
Hardware: PC Linux
: P3 major (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
Keywords: PatchAvailable
Depends on:
Reported: 2002-07-12 16:50 UTC by ast
Modified: 2011-03-27 18:00 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description ast 2002-07-12 16:50:28 UTC
mod_proxy issues the SIZE command for ftp transfers to determine the size
of the object to be transferred and sends this as the Content-Length to the
client. Unfortunately 'smart' ftp servers use the current transfer type
to determine the file size. In case of the default type which is ASCII after
login these servers include a LF to CRLF conversion in the length 
The result is a hanging transfer as the amount of bytes advertised in the
Content-Length header is larger than the amount of bytes delivered by the
ftp server.

Example with a command line ftp client:

$ runsocks ftp ftp.hu-berlin.de
Connected to vinus.rz.hu-berlin.de.
220-               Welcome to the Humboldt-University of Berlin
220-                             ftp.hu-berlin.de
220 ftp.hu-berlin.de FTP server ready.
Name (ftp.hu-berlin.de:ast): ftp
331 Guest login ok, send your complete e-mail address as password.
230-All logins and traffic are logged and analysed, if you
230-do not accept this policy, do not log in!
230-hello user at p5084739E.dip.t-dialin.net
230-local time is Fri Jul 12 17:52:31 2002
230-session number 95 in this class
230-current session limit 120
230-contact: ftpadm@rz.hu-berlin.de
230 Guest login ok, access restrictions apply.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> quote SIZE 
213 2824953
ftp> bin
200 Type set to I.
ftp> quote SIZE 
213 2814231
ftp> bye
221-You have transferred 0 bytes in 0 files.
221-Total traffic for this session was 1057 bytes in 0 transfers.
221-Thank you for using the FTP service on ftp.hu-berlin.de.
221 Goodbye.

Thus mod_proxy must set the transfer type prior to issuing of the SIZE
command to assert, that the SIZE command returns the proper object size.
The following one line patch asserts this:

--- proxy_ftp.c.orig    Fri Jul 12 18:19:04 2002
+++ proxy_ftp.c Fri Jul 12 18:22:50 2002
@@ -1072,6 +1072,7 @@
         get_dirlisting = 1;
     else {
+        ftp_set_TYPE(r, ctrl, xfer_type);
         ap_bvputs(ctrl, "SIZE ", path, CRLF, NULL);
         ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, 
"FTP: SIZE %s", path);
Comment 1 William A. Rowe Jr. 2011-03-27 18:00:09 UTC
If this logic is still true, it remains an issue.