Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

Java FTP client libraries reviewed

Learn how the available libraries stack up against each other

  • Print
  • Feedback

Let's imagine a situation where we want to write a pure Java application that must download files from a remote computer running an FTP server. We also want to filter downloads on the basis of remote file information like name, date, or size.

Although it is possible, and maybe fun, to write a protocol handler for FTP from scratch, doing so is also hard, long, and potentially risky. Since we'd rather not spend the time, effort, or money writing a handler on our own, we prefer instead reusing an existing software component. And plenty of libraries are available on the World Wide Web. With an FTP client library, downloading a file can be written in Java as simply as:

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 quality Java FTP client library that matches our needs is not as simple as it seems; it can be quite painful. It takes some time to find a Java FTP client library. Then, after we find all the existing libraries, which one do we select? Each library addresses different needs. The libraries are unequal in quality, and their designs differ fundamentally. Each offers a different set of features and uses different types of jargon to describe them.

Thus, evaluating and comparing FTP client libraries can prove difficult and confusing. Reusing existing components is a commendable process, but in this case, starting out can be discouraging. And this is a shame: after choosing a good FTP library, the rest is routine.

This article aims to make that selection process short, easy, and worthwhile. I first list all available FTP client libraries. Then I define and describe a list of relevant criteria that the libraries should address in some way. Finally, I present an overview matrix that gives a quick view of how the libraries stack up against each other. All this information provides everything we need to make a fast, reliable, and long-lasting decision.

FTP support in JDK

The reference specification for FTP is Request for Comments: 959 (RFC959). Sun Microsystems provides an RFC959 implementation in the JDK, but it is internal, undocumented, and no source is provided. While RFC959 lies in the shadows, it is actually the back end of a public interface implementing RFC1738, the URL specification, as illustrated in Figure 1.

Figure 1. FTP support in JDK. Click on thumbnail to view full-size image.

An implementation of RFC1738 is offered as standard in the JDK. It does a reasonable job for basic FTP transfer operations. It is public and documented, and source code is provided. To use it, we write the following:

URL url = new URL("ftp://user01:pass1234@ftp.foo.com/README.txt;type=i");
URLConnection urlc = url.openConnection();
InputStream is = urlc.getInputStream(); // To download
OutputStream os = urlc.getOutputStream(); // To upload


FTP client support in JDK strictly follows the standard recommendation, but it has several downsides:

  • Print
  • Feedback

Resources