Home >Java >javaTutorial >How to Maintain TLS Session Reuse for Data Connections in FTPS with Apache Commons Net?
How to Maintain TLS Session for Data Connection in FTPS with Apache Commons Net
Problem:
Connecting to an FTPS server that requires data connection to use the same TLS session as the control connection using Apache Commons Net.
Solution:
Requirement:
The server must support TLS session reuse for data connections.
Apache Commons Net Overriding:
Override the _prepareDataSocket_ method in a custom FTPSClient implementation to manage session reuse, similar to what Cyberduck does in its FTPClient.java.
JDK Compatibility:
In Java 8u161 and later, session reuse may not work by default. To enable it:
System.setProperty("jdk.tls.useExtendedMasterSecret", "false");
Alternative Implementation:
An alternative implementation can be found in the following Apache Commons Net JIRA issue: https://issues.apache.org/jira/browse/NET-408.
Android-Specific Considerations:
For Android, bypass SDK restrictions to access reflection fields for session management: https://issues.apache.org/jira/browse/NET-776.
Post-Java 8u161 Changes:
In newer versions of Java, sessionsByHostAndPort should be used instead of sessionHostPortCache.
The above is the detailed content of How to Maintain TLS Session Reuse for Data Connections in FTPS with Apache Commons Net?. For more information, please follow other related articles on the PHP Chinese website!