Search code examples
javahadoopftpapache-commonsftps

How can I configure Apache FTPFileSystem java class to use FTPSClient instead of the FTPClient


I am using to Apache Commons library to access files using on FTP/FTPS in my application. The architecture of the app doesn't allow to initiate the FTPClient, in my case I need to use the Apache FTPSClient.

The interface only allows me to pass the path to file, configuration and a FileSystem implementation.

Is there a property to set or another way to configure the FTPFileSystem to use the FTPSClient instead of the FTPClient?


Solution

  • FTPFileSystem does not support FTPS. It cannot create FTPSClient.

    You should have to create your own implementation of FileSystem based on FTPFileSystem (changing implementation of open), where you initialize the client as FTPSClient not FTP client. i.e:

    FTPSClient client = new FTPSClient();

    You can associate it with ftps:// URLs using:

    conf.set("fs.ftps.impl", "com.myproject.MyFTPSFileSystem");
    

    And you might need to set below property for the client to enter local passive mode:

    conf.set("fs.ftp.data.connection.mode", "PASSIVE_LOCAL_DATA_CONNECTION_MODE");