commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sebb (JIRA)" <>
Subject [jira] [Commented] (NET-500) FTPClientExample does binary transfers by default instead of ASCII as stated in documentation
Date Sun, 03 Feb 2013 14:44:13 GMT


Sebb commented on NET-500:

The FTPClient class initialises its transfer mode to ASCII, and as far as I can tell, the
default transfer mode for FTP servers is supposed to be ASCII.

RFC959 - e.g. - says at the start of page 28 in the section
on the TYPE command:

"The default representation type is ASCII Non-print."

So in theory, it should not be necessary to specify ASCII mode.

However I just checked various public FTP servers, and only 17 of 45 defaulted to ASCII, the
rest were BINARY.

This means that the Javadoc for FTPClient#setFileType() is misleading/incomplete.
Although the default setting of the FTPClient variable is ASCII, unless the server default
is also ASCII, it won't work correctly.

The fix for the example code is as you suggest; that will always work.

The simplest fix for FTPClientsetFileType() would be to update the Javadoc to make it clear
that the default only works if the server honours the RFC.

It would be possible to always set the server to ASCII mode upon initial connection, but that
is wasteful if the user wants binary mode. Otherwise, the code would have to detect that the
TYPE had not yet been sent and send it just before it is first needed. Not sure it's easy
or sensible to do that.

It does not appear to be possible to find out what the default transfer mode is.
Some servers provide this info during login, but if not, there does not seem to be a standard
way to find out, except by initiating a dummy transfer (which is expensive).
> FTPClientExample does binary transfers by default instead of ASCII as stated in documentation
> ---------------------------------------------------------------------------------------------
>                 Key: NET-500
>                 URL:
>             Project: Commons Net
>          Issue Type: Improvement
>          Components: FTP
>    Affects Versions: 3.2
>         Environment: all environments concerned
>            Reporter: Michael Frick
>            Priority: Trivial
>              Labels: patch
>             Fix For: 3.2
> Following change should be added to the FTPClientExample class, otherwise 
> the default ASCII setting will not be set.
>   if (binaryTransfer) {
>                 ftp.setFileType(FTP.BINARY_FILE_TYPE);
>             }
>             // Added else to set correct default file type / M. Frick 2013-02-03
>             // Default ftp class file type seems to be binary!
>             else
>             {
>                 ftp.setFileType(FTP.ASCII_FILE_TYPE);
>             }
>             // End of change / M. Frick 2013-02-03

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see:

View raw message