Home  >  Article  >  Java  >  How Can I Resolve the 'Remote Host Closed Connection During Handshake' Error When Connecting to an FTPS Server with TLS Session Reuse?

How Can I Resolve the 'Remote Host Closed Connection During Handshake' Error When Connecting to an FTPS Server with TLS Session Reuse?

Linda Hamilton
Linda HamiltonOriginal
2024-11-12 17:23:021053browse

How Can I Resolve the

Connecting to FTPS Server with TLS Session Reuse

When attempting to establish a connection with an FTPS server, the client may encounter the "Remote host closed connection during handshake" error. This typically occurs when the server requires the same TLS session to be used for both the control and data connections. Apache Commons Net's FTPS implementation does not inherently support this behavior.

To resolve this issue and ensure TLS session reuse:

  1. Implement Custom FTPSClient:

    • Override the prepareDataSocket method in the FTPSClient class to reuse the TLS session.
    • Implement logic similar to the one found in Cyberduck's FTPClient.java.
  2. Override DefaultFtpsSessionFactory:

    • Override the createClientInstance() method in DefaultFtpsSessionFactory.
    • Return your custom FTPSClient implementation.
  3. Handle JDK 8u161 Issue:

    • Set the "jdk.tls.useExtendedMasterSecret" system property to false to address compatibility issues in JDK 8u161.
  4. Use SessionsByHostAndPort:

    • On newer Java versions, use the sessionsByHostAndPort map in SSLSessionContext instead of sessionHostPortCache for session reuse.
  5. Bypass Android SDK Restrictions (Optional):

    • If working on Android, bypass SDK restrictions to access fields by reflection.

Remember, this solution is a workaround and may not provide a long-term fix.

The above is the detailed content of How Can I Resolve the 'Remote Host Closed Connection During Handshake' Error When Connecting to an FTPS Server with TLS Session Reuse?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn