SocketTimeoutException

Help
2005-07-29
2013-02-24
  • David Timerman
    David Timerman
    2005-07-29

    It appears to be coming from line 210 in DataConnection

                        try
                        {
                            ssock.setSoTimeout(Settings.connectionTimeout);
                            sock = ssock.accept();
                        }

    from the ssock.accept();

    > PORT 10,10,10,152,5,5

    200 PORT Command successful.

    > 200 PORT Command successful.

    > RETR performance.xsd

    > > RETR performance.xsd

    150 Opening ASCII mode data connection for performance.xsd (1704 Bytes).

    > 150 Opening ASCII mode data connection for performance.xsd (1704 Bytes).

    java.net.SocketTimeoutException: Accept timed out

        at java.net.PlainSocketImpl.socketAccept(Native Method)

        at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:353)

        at java.net.ServerSocket.implAccept(ServerSocket.java:448)

        at java.net.ServerSocket.accept(ServerSocket.java:419)

    Got IOException while trying to open a socket!

    > Got IOException while trying to open a socket!

    Can't connect socket to ServerSocket

    > Can't connect socket to ServerSocket

        at net.sf.jftp.net.DataConnection.run(DataConnection.java:210)

        at java.lang.Thread.run(Thread.java:534)

    java.lang.NullPointerException

    > java.lang.NullPointerException

    I am using an Active connection

    My program was working perfectly up until today. Its task is to Ftp to a specific remote server and download specific files in Binary mode. I am not sure why this is happening - wondering if I am doing something wrong or if there could be a bug... Included is important code in my client application :

      public static void main(String[] args) {
        JftpClient client = new JftpClient();

        File[] files = new File[1];
        files[0]=new File("file1.xsd");

        try {
          client.openConnection(<ip>, <username>,
                                                    <passwd>);
          client.setAscii();
          client.downloadFiles(files);
          client.closeConnection();
        }
        catch (Exception e) {
          e.printStackTrace();
        }
      }

      public void openConnection(String host, String username,
                                          String password) throws Exception {
        Settings.setProperty("jftp.ftpPasvMode", false);
        con = new net.sf.jftp.net.FtpConnection(host);
        con.addConnectionListener(this);
        con.setConnectionHandler(handler);
        con.login(username, password);
        // Waits for the connection to be made, otherwise, throws exception
        while (!isConnected) {
          try {
            Thread.sleep(10);
          }
          catch (Exception ex) {
            ex.printStackTrace();
          }
        }
        if (con == null || !isConnected) {
          throw new Exception("Connection could not be established");
        }
      }

       public void downloadFiles(File[] downloads) {
        String parentDir = con.getCachedPWD();
        for (int x = 0; x < downloads.length; x++) {
          File file = downloads[x];
          String filePath = file.getParent();
          //if the file is to be downloaded from a non-parent directory, change the path
          if (filePath != null) {
            con.chdir(filePath);
          }
          String fileName = file.getName();
          con.download(fileName);
            //changes directory to the parent if the directory has been altered
          if (filePath != null) {
            con.chdir(parentDir);
          }
        }
      }

    If anyone could shed some light on this issue for me that would be very helpful

    Thank you

     
    • Cyberdemon
      Cyberdemon
      2005-08-05

      Hi!

      My first guess is that you might have some kind of firewall enabled that blocks the incoming request from the server somewhere in your network or that something is running on port 1285 (the port represented by the port command). Can you check that please?

       
    • David Timerman
      David Timerman
      2005-10-06

      I'm sorry it has been months since i've gotten back to this problem... anyways, it doesnt look like the issue is the firewall - it seems that this error occurs only when a file is not found on the server during a download.

      it fails at " sock = ssock.accept(); " in DataConnection

       
    • Jake Kasprzak
      Jake Kasprzak
      2005-10-14

      Hello.

      Well, after looking into this a little further, I think I can tell you the best way to deal with this. It does appear that the reason that this exception is thrown is because the file you are trying to download is not there. A timeout will occur at that line if that happens. And if you would prefer to not have that exception thrown, the best way to handle this would be to list the files in the remote directory, then check that list for that file. As you may know, you can use the sortLs() method in FtpConnection.java to get the list of files, then you can check that array of strings for the file you are trying to download. If you do that, then I'm sure you will not see this exception get thrown again.

      If it does happen again, though, or if you have any further questions or comments, do not hesitate to post them here.

      Thanks,

      J.K.

       
    • David Timerman
      David Timerman
      2005-10-17

      thank you for your help - i figured it would be something like that. i will implement your ls suggestion.

      again, very appreciated