Home > Java > javaTutorial > body text

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

Linda Hamilton
Release: 2024-11-12 17:23:02
Original
1010 people have browsed it

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template