FTP with Java

FTP with Java

Normally, from within a Java applet you can create a instance using the “ftp://” protocol handler. But you may need a third-party library to access FTP from a Java application. There is a package called that you can use, but it is non-standard and not guaranteed to be available on every platform. By using a third-party package, you can ensure your program will work everywhere by distributing the classes with your program. One package that provides FTP functions, as well as others, is called NetComponents, available from It contains a package called and a class called FTPClient with which you can access ftp from a program. I’ve included a simple example of how to fetch a file from an FTP server and write it to the local file system:

 import*;*;public final classFTP {  public static final voidmain(String[] args) {    FTPClientclient;    client = new FTPClient();try {      client.connect("");if(!FTPReply.isPositiveCompletion(client.getReplyCode())) {client.disconnect();System.err.println("FTP server refusedconnection.");   return;      }client.login("anonymous","user@hostname");client.setFileType(;client.retrieveFile("docs/source_license.pdf",           newFileOutputStream("source_license.pdf"));client.quit();client.disconnect();    }catch(IOException e) {e.printStackTrace();    }  }}

See also  How IoT Tech Will Transform Logistics

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist