Uploaded image for project: 'Commons Net'
  1. Commons Net
  2. NET-296

java.net.SocketException: Operation timed out error while entering Passive mode

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Blocker
    • Resolution: Duplicate
    • 2.0
    • None
    • None
    • None
    • Windows XP, JDK 1.5.0_15, commons-net-2.0-jdk14.jar

    Description

      Hi,

      I am getting the following error while trying to connect to the FTP (Explicit).

      java.net.SocketException: Operation timed out: connect:could be due to invalid address.

      I am facing this error when i am running the code from the client machine which is in different domain...If i run the same code in the domain where ftp exists..it works fine without any issue...below is my code and the trace log....Pls help.

      FTPSClient client = new FTPSClient("TLS",false);
      client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
      boolean _ftp_login = false;

      try {
      String[] hname = ftpurl.split("//");
      client.setAuthValue("TLS");
      client.setRemoteVerificationEnabled(false);

      client.connect("ftp.kotaklifeinsurance.com",22);

      int reply = client.getReplyCode();
      client.execPBSZ(0);
      client.execPROT("P");

      if (!FTPReply.isPositiveCompletion(reply))

      { client.disconnect(); System.out.println("openFTPClient(): FTP server refused connection."); throw new Exception("FTP server refused connection."); }

      else {
      try

      { _ftp_login = client.login(userID, password); }

      catch (Exception e)

      { throw e; }

      if (_ftp_login) {

      client.enterLocalPassiveMode();

      if (client.printWorkingDirectory() == null)
      throw new Exception("Current working directory returned is null");

      client.changeWorkingDirectory("/XYZ/");

      fis = new FileInputStream(localfile);
      ins = (InputStream)fis;

      boolean flag = client.storeFile(filename,ins);
      System.out.println("File saved to FTP : "+flag);

      Error Trace :

      220 Unauthorized Access Prohibited.
      AUTH TLS
      234 AUTH command ok. Expecting TLS Negotiation.
      PBSZ 0
      200 PBSZ command successful.
      PROT P
      200 PROT command successful.
      USER userid
      331 Password required for userid.
      PASS password
      230 User logged in.
      PWD
      257 "/" is current directory.
      CWD /XYZ/
      250 CWD command successful.
      PWD
      257 "/XYZ" is current directory.
      TYPE A
      200 Type set to A.
      MODE I
      501 'MODE I': parameter not understood.
      STRU F
      200 STRU F ok.
      PASV
      227 Entering Passive Mode (192,168,201,220,195,108).
      java.net.SocketException: Operation timed out: connect:could be due to invalid address
      at java.net.PlainSocketImpl.socketConnect(Native Method)
      at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:331)
      at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:196)
      at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:183)
      at java.net.Socket.connect(Socket.java:478)
      at java.net.Socket.connect(Socket.java:428)
      at java.net.Socket.<init>(Socket.java:335)
      at java.net.Socket.<init>(Socket.java:150)
      at com.ibm.jsse.bs.<init>(Unknown Source)
      at com.ibm.jsse.JSSESocketFactory.createSocket(Unknown Source)
      at org.apache.commons.net.ftp.FTPSSocketFactory.createSocket(FTPSSocketFactory.java:48)
      at org.apache.commons.net.ftp.FTPClient.openDataConnection(FTPClient.java:502)
      at org.apache.commons.net.ftp.FTPSClient.openDataConnection(FTPSClient.java:494)
      at org.apache.commons.net.ftp.FTPClient.__storeFile(FTPClient.java:374)
      at org.apache.commons.net.ftp.FTPClient.storeFile(FTPClient.java:1379)

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              ksharisomayaji Hariprasad K S
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: