FTPS in Java

Introduction

This article demonstrates how Java clients can connect to FTPS servers to transfer files, using edtFTPj/PRO.

Detail

FTPS is a protocol for transferring files securely via FTP. Basically, the standard FTP protocol is encrypted via secure sockets, or SSL. For Java clients to communicate to FTPS servers, the client side of the FTP protocol and SSL must be implemented in Java.

It is not realistic for most applications to directly implement the FTPS protocol. Instead, it is best to acquire an implementation that is well tested and feature rich - for example, edtFTPj/PRO. The following example demonstrates how a client using edtFTPj/PRO can connect to an FTPS server and list the current directory on the server. It downloads every file in the directory:

import com.enterprisedt.net.ftp.*;

SecureFileTransferClient client = new SecureFileTransferClient();

// set params
client.setRemoteHost(host);
client.setUserName(username);
client.setPassword(password);
client.setProtocol(Protocol.FTPS_EXPLICIT);

client.connect();

// get a directory listing
FTPFile[] files = client.directoryList();
for (int i = 0; i < files.length; i++) {
 System.out.println(files[i].toString());
 client.downloadFile(files[i].getName(), files[i].getName());
}

client.disconnect();

Also consider SFTP

For many applications SFTP might be a better choice. Why? See FTPS vs SFTP.