Java FTP client library review
Understanding the available libraries is compared to each other
Summary
This article explains how to use the library to write FTP client code in Java language. It compares a full list of FTP libraries to demonstrate the advantages and disadvantages of each library, and help decision makers choose the appropriate library for them. In addition, this paper explains how Fa? ADE mode changes management when replacing a library. Finally, the author Jean-Pierre Norguet discusses and solves some problems caused by lack of authoritative instructions.
Let us assume a scenario: We have to write a pure Java application that must download files from the remote computer running the FTP server. We also filter downloads via remote file information, like name, date, or size.
Write yourself to write an FTP protocol, although it is possible, and it may be interesting. But this is also possible to have difficulties, spend long, and potential risks. Since we refuse to spend time, energy, or money to write a processor, we recommend using a reusable existing software component. There is a large number of libraries on the World Wide Website. With an FTP client library, download a file with Java language is as simple as the following:
FTPCLIENT FTPCLIENT = New ftpclient ();
FTPCLIENT.CONNECT ("ftp.foo.com", "user01", "pass1234");
FTPCLIENT.DOWNLOAD ("C: // Temp //", "Readme.txt");
// Eventually Other Operations Here ...
FTPClient.disconnect ();
Looking for a high quality Java FTP client that is suitable for us is not as simple as he looks like him; it may be quite difficult. It takes some time to find a Java FTP client library. Then, which one we do after we find all the existing libraries? Each library is suitable for different needs. The library is not equal in quality, and their design has essentially different. Each provides a different set of properties and describes them using different types of jars.
Therefore, the calculation and comparison of FTP client libraries prove that it is difficult and confusing. Repeating that existing components is a recommended process, but in this example, start it is also frustrating. And this is a bit ashamed: after choosing a good FTP library, the rest is the routine.
This article is intended to make the selection process, easy, and valuable. I first list all the FTP client libraries. Then, I define and describe a form of the relevant standard that libraries should be found in some way. Finally, I lists a total browsing matrix, which gives a quick browsing of the process between the library. All information provides us to make everything you need to make a rapid, reliable, and long-term decision.
Use JDK (Java Development Tool Set) FTP Support
Access specification for FTP is a request for comments: 959 (RFC959). Sun Microsystems provides an RFC959 of JDK. But it is internal, non-documentized, and does not provide any resources. When the RFC959 is not disclosed, it is actually a rear terminal that performs an RFC 1738 and a URL specification. Figure 1.
Figure 1. Using JDK's FTP support.
An execution process of RFC1738 is given in JDK as a standard. It makes a reasonable work for basic FTP. It is public, documentated, and provides source code. To use it, we can write the following statement:
URL URL = New URL ("ftp: // USER01: pass1234@ftp.foo.com/readme.txt; type = i");
UrlConnection URLC = URL.OpenConnection ();
InputStream IS = urlc.getinputstream (); // to Downloadoutputstream OS = Urlc.getOutputStream (); // To Upload
Use JDK's FTP client strict compliance with standard recommendations, but it has the following instructions:
It is fundamentally different from the third party's FTP client library; these execution RFC959 instead of RFC1738
RFC959 is executed with most desktop FTP client tools. Many Java programmers use these tools to connect to the FTP server. As an attempt, these tools and likely to prefer similar RFC959 libraries.
The URL and the URLConnection class only open the stream for communication. The Sun library does not provide direct support for the constructed original FTP server response to a more suitable Java object such as String, File, Remotefile, or Calendar. So we have to write more code, just to write data into a file or start a directory list.
As explained in the 3.2 part of RFC1738, "optimized", the FTP URL requires a shutdown (control) connection after each operation. This is a waste of transmitting many small files and is not efficient. Moreover, it is specifically limited that the FTP server may put the overhead of this. It is considered to be a vicious network attack or abuse to refuse to provide further services.
Finally, it lacks several useful properties.
Due to all or for some reason, a third party library can be preferred. The following sections list the libraries for selectable third parties.
Library comparison
The library I want to compare is listed in the table below. They all comply with access to the FTP specification. Next, I have provided the supplier name and library name (with a bevel word). Resources includes links to each product website. In order to use these libraries quickly, I also mentioned its main FTP client class.
1. Jscape, INET FACTORY: com.jscape.inet.ftp.ftp
2. / N software, ip * Works: ipWorks.ftp
3. Enterprise Distributed Technology, Java FTP Client Library: om.enterprisedt.net.ftp.ftpclient
4. IBM AlphaWorks, FTP Bean Suite: com.ibm.neetwork.ftp.protocol.ftpprotocol
5. SourceForge, JFTP: Net.sf.jftp.net.ftpConnection
6. THE
Jakarta
Project, Jakarta Commons / Net: Org.apache.commons.Net.ftp.ftpClient
7. Javashop jnetBeans: jshop.jnet.ftpclient
8. Sun, JDK: Sun.Net.ftp.ftpclient
9. Florent Cueto, Javaftp API: com.cqs.ftp.ftp
10. BEA Petrovicova, JFTP: CZ.DHL.FTP.FTP
11. The Globus Project, Java Cog Kit: org.globus.io.ftp.ftpclient
note:
When writing this article, IBM is evaluating the suitability of AlphaWorks FTP Bean Suite on its site. Now downloading all users.
Jakarta Commons / Net is instead of Savarese NetComponents. Savarese NetComponents will not be developed again.
Javashop JNetBeans seems to have been abandoned. When writing this article, the site has been offline for more than a month, and I didn't receive any response to the request.
standard
At this point, I have already introduced and list the available libraries. Now, I list the relevant standards for each library for the evaluation. I am quantified for each standard, and the abbreviation (bold) used in the final comparison matrix is placed together.
Product support
The library provides users with a product document, compiled Java document, sample code, and an application example including comments and interpretation. Additional support can be provided to the user through a forum, an email list, a contact with an email address, or an online fault tracking system. / N software provides additional support to additional charges.
A support for administrators is an important factor in quick support. Support administrators can be:
A volunteer (i)
A volunteer group (g)
A paid expert group provides support (P)
license
For business projects, the product license is an important thing to consider from the beginning. Some libraries can reuse in commercial products freely, but others cannot. GPL (GNU General Public License) is a powerful, conditional license, but Apache Software licenses only require descriptions in reuse products.
Commercial license limits the number of programming of the library development workstation, but does not limit the distribution of the library itself.
For non-commercial projects, the license is more like a philosophical problem, and a free product is grateful.
The license can be:
Business (C)
GPL (g)
Free (F); however, it has to detect a free license limit condition.
Some library suppliers require alternative, limited licenses.
Provided source code
The software library of a closed source code, black-box can be angry. Due to the following reasons, the source code will make him more convenient:
When the application code performs a fault, enter the library code resource to help you understand the behavior of the library.
Source code contains useful comments
Source code can be adjusted quickly to adapt to new needs
Demonstration source code can be detected
life
The library has been tested, repairs faults and support from their first public release. Since the number of versions change in the library. I am based on the standard of the earliest publication year.
Directory list support
Retrieving remote file information from the server (name, size, date) is important in most applications. The FTP protocol provides NLST instructions to retrieve file names; NLST naming is accurately designed for program calls. The list command provides more file information; like RFC959 comments: "Since information on the file may be automatically used from the system to the system, this information is difficult to use in a program, but is quite useful for human users. "There is no other standard method to retrieve file information; therefore, the client library attempts to call the List response. However, this is not an easy thing: since there is no authoritative recommendation available for List corresponding format, the FTP server uses a different format:
UNIX type: drwxr-xr-x 1 USER01 FTP 512 JAN 29
23:32
PROG
Alternative UNIX Type: DRWXR-XR-X 1 User01 FTP 512
Jan 29 1997
PROG
Alternative UNIX type: DRWXR-XR-x 1 1 1 512 Jan 29
23:32
PROG
Use UNIX type symbolic link: lrwxr-xr-x 1 USER01 FTP 512 JAN 29
23:32
PROG -> PROG2000
Weird UNIX type (no spacing between users and groups): DRWXR-XR-X 1 UserNameftp 512 Jan 29
23:32
PROG
MS-DOS type:
01-29-97
11:32 PM
Macintosh Type: DRWXR-XR-X Folder 0 Jan 2923: 32
PROG
OS / 2 Type: 0 DIR
01-29-97
23:32
PROG
UNIX type, followed by the MS-DOS type, which is the most widely used format.
Java FTP client library tries to understand and automatically detect as much format. In addition, they provide different options for handling unpredictable format answers:
An additional method returns the original FTP response as a string (s)
An additional method, returning the original string set, each row / file a string (c)
A framework (P) supporting a plug-in
Most libraries capture the List response and organize the original file information into a Java object, such as the JSCAPE INET library, the following code retrieves and calls the received file information to a directory list:
Java.util.enumeration files = ftpclient.getdirListing ();
While (files.hasmorelements ()) {
Ftpfile ftpfile = (ftpfile) FILES.NEXTELEMENT ();
System.out.println (ftpfile.getFileName ());
System.out.println (ftpfile.getFileSize ());
// etc. Other Helpful Methods Are Detailed in javadoc
}
The "Legacy Problem Solution" section will further discuss the directory list.
Time label search
In many cases, we are interested in the recent modified time label of a remote file. Unfortunately, no RFC introduces a standard FTP command to retrieve this information. There are two practical methods below:
1. Retrieve this information from the List response by capturing the server. However, just like you learned in front, the List response varies in the FTP server, and the time tag information is sometimes incomplete. With UNIX format, there is no accuracy when there is more than one year: only date and year, no hours or minute part.
2. Use non-standard MDTM commands. This command specifically retrieves the latest time label for a remote file. Unfortunately, not all FTP servers do this command.
A complex alternative support for the MDTM command is to send a original MDTM command and capture the command. Multiple libraries provide a way to send a original FTP command, like:
String timestampstring = ftpclient.commad ("MDTM Readme.txt");
Another possible aspect is the FTP service enables GMT (Greenwich Time) to return time information. If the known server time zone is separated from the FTP communication, the java.util.timezone.getOffset () function helps adjust the difference between the time zone. For more information on this function, please see the JDK document.
"Legacy Problem Solution" section further discusses the file time tag retrieval.
Firewall
Typical, firewalls are set in a private corporate network and public network, such as the Internet. It manages access from private networks to public networks, but accesses from public networks to private networks veto.
SOCKS is a public, unified protocol developed as an Internet firewall gateway. JDK supports SOCKS 4 and SOCKS 5 agents. They are controlled by some part of the library. As an alternative, the JVM command line can set SOCKS proxy parameters: java -dsocksproxyport = 1080 -dsocksproxyhost = SOCKS.FOO.USERNAME = USER01 -DJAVA.NET.SOCKS.PASSWORD = pass1234 ... other A universal SOCKS agent support option is "SOCKS" client device in the TCP / IP layer below.
JDK also supports HTTP channels, which are not allowed to upload FTP. / n software's IP * WORKS allows you to set HTTP channel parameters.
Most libraries support both active, and supported passive connections: The passive connection is useful when the client is connected to the firewall that is introduced to a higher port. The RFC1579 discusses this friendly firewall function in more detail. Some products are filed for active and passive links as Port and PASV commands, respectively.
Parallel transfer
In a desktop app, everything is frozen when the transfer is started in the main list. Some libraries are automatically served in a separate online parallel event loop, so we don't have to create and manage our own threads.
JavaBean Manual Support
Some libraries implement the JavaBean manual. JavaBean is allowed by default to programming, which is specialized in the main Java IDE.
/ N software IP * Works, JavaBean design is an event-based (for example: ipworks.ftp.listdirectory () function). Although it remains synchronously and quite safe, some programmers still find it more or clumsy in the server-side applications.
Process supervision
Some libraries perform process supervision. Process Supervision Support makes an event listener that performs tracking of any FTP transfer easier. This feature is useful when developing a friendly user interface.
Transmission type
The RFC959 3.1.1 defines several transmission types, two of which are common ascii nonprint (default) and Image (also known as binary). Some libraries can be set according to the file extension, such a method is rarely useful in modern information systems, and the other transmission type has been discarded and is not supported by any Java.
Other standard description
All libraries are run at least on JDK 1.2.x or updated. Most should run on JDK 1.1.x, even JDK 1.0.x.
All libraries are pure Java languages.
The comparison matrix lists other obvious standards.
Java FTP Client Library: Comparison Matrix
The last comparison matrix now appears. It is column on the left is the standard, top listed is the library, which lists the top libraries corresponding to the left standard. In the unit, Y represents "Yes"; other abbreviations explain in the password of the above standard list (the letter marked with a bold word) and the password of the table.
When I choose a library, I have several suggestions:
Server-side application, I recommend Jakarta Commons / Net library
Jscape's inetfactory I found that it is the most easy to use library
/ N software IP * Works is part of a widely used product that contains FTP encryption support.
Java Cog Kit also performs Gridftp. Gridftp is an interesting new generation file transfer system.
When writing this article, I recommend not using IBM's AlphaWorks FTP Bean Suite and Javashop JNetBeans under the current conditions.
Other libraries are absolutely decent and suitable for your needs; please refer to the matrix.
See: http://www.javaworld.com/javaworld/jw-04-2003/ftp/jw-0404-ftptable.html
Change management
At some point in our project, especially when the project is completely tested, it is likely that we want to modify our library. Such a change affects all our calling code: Our class will no longer be compiled, and some application part must be re-encoded to fit the different methods of method names and new libraries. Since management such a change prove is very annoying, especially when the project is fast, we should limit the change in one individual class when it is a key resource. Typically, we applies the FA? ADE mode, as FTP library When the terminal is followed, see Figure 2.
Figure 2 FA? ADE mode is applied to an FTP library
Applying a good impact on the FA? ADE mode to the FTP library is that we can add a value to the library. For example, we can write a FA? ADE program, with it to download the entire remote directory to a local compressed file or a program. Any basic attribute that is lacking in the library.
Finally, two library runtimes that have the same signature are not necessarily the same. Therefore, from a library to another library, it can also affect the runtime of our application. Such an impact is extraction and uncomfortable. Because it is found that the difference between runtime is much more, although detailed testing may help.
In the above-mentioned criteria, I concisely describe several problems that cannot be solved. In this section, I will discuss and solve them; I recommend a long-term solution and a short-term solution.
Directory list
Any authority manual for List response results in many different FTP servers. This lack is the biggest problem with FTP client programmers, and it is still an open problem.
Since the problem is fundamentally on the definition of the protocol, I recommend the relevant authoritative organization, the Internet Engineering Task Organization (IETF), defines the LIST response structure with a new reference document manual (a RFC).
The process is long, and the most flexible solution is to use a library that provides a frame of formatting an insertable format.
File time label search
Just as I just discussed, there is no way to retrieve the latest modification time label for a remote file via FTP. I recommend two long-term solutions for the time label transmitted from the server to the client:
1. Include and complete time tags in the List response
2. Standardized MDTM commands and responses
For both options, the time zone problem of the server is considered during the communication process.
Again, because the problem is fundamentally in the protocol definition, I recommend IETF to define one or both of the two programs as an authoritative specification.
At the same time, the most common short-term solution is to use libraries that are supported by List and MDTM response, and develop these two attributes.
Change management
In the above-mentioned related part, I recommend a FA? ADE mode to reduce changes in the replacement process. As I said, the pattern is not a universal medicine, because the lack of behavior in the library can still affect our entire application within runtime, it is difficult to control.
Because this is a pure coding problem, I recommend Sun's publishing a standard design Good API to define an accurate procedure and behavior. This program can be implemented in anyone, including Sun. Programmers can use interface programs and support them with their specified execution procedures. Any switching from a library to another produces a minimum impact on the rest of the application. Java Mail and JDBC (Java Database Connections) API is an exemplary reference unit.
The Java FTP API Standardization project is intended to organize a user, developer, and supplier alliance, and introduce improvements to the Java community process as a Java specification request. Your support is of course useful to the project, and its home page can be found in Resources.
I need the best library for you.
In this article, I explained how to write FTP client code with Java and list the FTP client support for JDK and third-party libraries. I also showcase criteria comparisons between important standards and libraries to consider during the process of calculating different libraries. I hope that the decision makers find a useful tip in this article when the selection of the Java FTP client library is to make the best decision. Finally, I explain the different problems that are generally existing for all FTP libraries, and recommend short-term solutions and long-term solutions that may be used by authoritative institutions like IETF and SUN. I hope these pilots and behaviors will help cast the future of the Java FTP client library.
About author
Jean-Pierre Norguet, Libre de Bruxelles University, Paris Libre de Bruxelles Socate Europe, the Java Development Team of IBM Task, as a three-year full-time leadership and coach. He is good at development of the entire application life cycle. It is now a member of the Belgian Brussels Survey Team to prepare a doctoral papers on the Internet audience analysis. His hobbies include art painting appreciation, watch the French cinema performance and enjoy a comfortable massage.