Although it is possible to use Java networking API (by using the interfaces and classes available in the packages java.net and javax.net) to write code that communicates with a FTP server, that approach is discouraged because you will have to spend a lot of time on understanding the underlying FTP protocol, implementing the protocol handlers, testing, fixing bugs… and finally you re-invent the wheel! Instead, it’s advisable to look around and pick up some ready-made libraries, and that definitely saves your time! The Apache Commons Net library is an ideal choice for developing FTP based applications. It’s not just for only FTP, but for all common standard internet protocols such as NNTP, SMTP, POP3, Telnet… to name just a few.

With built-in Java API, we can use the java.net.URLConnection to do some FTP operations such as listing files and directories, upload and download. However that is very limited in terms of controllability and flexibility.

So, if you are going to write a Java application that needs to communicate with a FTP server, go on with Apache Commons Net.

Download a zipped binary distribution of the library (commons-net-3.6-bin.zip) and extract the zip file to a desired location on your computer. The following screenshot shows content of the distribution:

Apache Commons Net distribution directory structure

You can find the following items included in the distribution:

So to compile and run your code, you must have commons-net-3.6.jar file present in your project’s classpath.

The package org.apache.commons.net.ftp contains interfaces and classes for working with FTP protocol. The FTPClient class implements necessary functions for developing a FTP client program.

And that’s only the first step. Check out our tutorials dedicated to Java FTP programming with Apache Commons Net library:

 



 

 

 

 


About the Author:

is certified Java programmer (SCJP and SCWCD). He started programming with Java in the time of Java 1.4 and has been falling in love with Java since then. Make friend with him on Facebook and watch his Java videos you YouTube.