Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8161351

Unable to connect to a Secure FTP site with self signed certificate

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version "1.8.0_91"
      Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
      Java HotSpot(TM) Client VM (build 25.91-b14, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Windows 7 SP1

      A DESCRIPTION OF THE PROBLEM :
      The following code runs successfully when I run it as stand alone using java.exe. However, it doesn't run from eclipse or in the Weblogic server. The ftp site has no issue connecting from any FTP clients.

      FTPSClient ftpsClient = new FTPSClient("TLS", false);
      ftpsClient.setAuthValue("TLS");
      ftpsClient.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));

      ftpsClient.connect("@host_name@",21);

      The SSL certificate for the FTP site is a self-signed certificate. Adding the certificate to Java trusted store didn't help either.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Try to connect to a secure FTP site using FTPSClient from commons-net jar from apache. The SSL certificate for the site must be a self signed certificate

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Must be able to connect to the secure ftp site
      ACTUAL -
      xception in thread "main" java.net.SocketException: Connection reset
      at java.net.SocketInputStream.read(SocketInputStream.java:189)
      at java.net.SocketInputStream.read(SocketInputStream.java:121)
      at sun.security.ssl.InputRecord.readFully(InputRecord.java:442)
      at sun.security.ssl.InputRecord.read(InputRecord.java:480)
      at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:927)
      at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1312)
      at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1339)
      at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1323)
      at org.apache.commons.net.ftp.FTPSClient.sslNegotiation(FTPSClient.java:259)
      at org.apache.commons.net.ftp.FTPSClient._connectAction_(FTPSClient.java:205)
      at org.apache.commons.net.SocketClient.connect(SocketClient.java:163)

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      xception in thread "main" java.net.SocketException: Connection reset
      at java.net.SocketInputStream.read(SocketInputStream.java:189)
      at java.net.SocketInputStream.read(SocketInputStream.java:121)
      at sun.security.ssl.InputRecord.readFully(InputRecord.java:442)
      at sun.security.ssl.InputRecord.read(InputRecord.java:480)
      at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:927)
      at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1312)
      at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1339)
      at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1323)
      at org.apache.commons.net.ftp.FTPSClient.sslNegotiation(FTPSClient.java:259)
      at org.apache.commons.net.ftp.FTPSClient._connectAction_(FTPSClient.java:205)
      at org.apache.commons.net.SocketClient.connect(SocketClient.java:163)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      FTPSClient ftpsClient = new FTPSClient("TLS", false);
      ftpsClient.setAuthValue("TLS");
      ftpsClient.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));



      ftpsClient.connect("@host_name@",21);

      int reply = ftpsClient.getReplyCode();
      if (FTPReply.isPositiveCompletion(reply)) {
      System.out.println("Connection successful");
      }
      System.out.println("IS Connected : " + ftpsClient.isConnected());


      if(ftpsClient.login("@user_id@","@password@")) {
      System.out.println("logged in ");
      }
      ---------- END SOURCE ----------

        1. log.txt
          79 kB
        2. JI9037073.java
          0.9 kB
        3. commons-net-3.3-ftp.jar
          132 kB
        4. commons-io-1.3.2.jar
          86 kB
        5. apache-commons-net.jar
          449 kB

            coffeys Sean Coffey
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: