Commons Net
  1. Commons Net
  2. NET-462

FTPClient in PASSIVE_LOCAL_DATA_CONNECTION_MODE cannot work when host have several different IP

    Details

      Description

      When host have several different IP and client setting to PASSIVE_LOCAL_DATA_CONNECTION_MODE,openDataConnection creating socket may use the unexpected ip。
      For example, The host have two Ips, one for intra and the another for extern, only the extern one can be connect with the outside。But when in PASSIVE_LOCAL_DATA_CONNECTION_MODE, FTPClient may be select the intra Ip, So it didn't work。
      So I change code like this, it can work normally by the specific ip.
      Code:
      In FTPClient.openDataConnection(String command, String arg),line 761 change as bellow:
      socket = socketFactory.createSocket();

      // add begin
      // local as client, transfer data must use the appointed local host
      socket.bind(new InetSocketAddress(getHostAddress(), 0));
      // add end

      After log in success,User can set the ip which he want to use by call the method in FTPClient:
      setActiveExternalIPAddress(String ip);

      1. ftp-bindlocal.diff
        2 kB
        Bogdan Drozdowski

        Activity

        Hide
        Bogdan Drozdowski added a comment -

        The attached patch fixes this by adding a new field in FTPClient. By calling setPassiveLocalIPAddress(), you can set the local address to bind to. The field will be used in the same place as in your code (but it is a separate value from what getHostAddress returns).
        In the meantime, you can create and install your own SocketFactory in the FTPClient. You can take DefaultSocketFactory class as an example and make you own factory, which will create sockes already bound to your local address. This will work even with the older versions of Commons-Net.

        Show
        Bogdan Drozdowski added a comment - The attached patch fixes this by adding a new field in FTPClient. By calling setPassiveLocalIPAddress(), you can set the local address to bind to. The field will be used in the same place as in your code (but it is a separate value from what getHostAddress returns). In the meantime, you can create and install your own SocketFactory in the FTPClient. You can take DefaultSocketFactory class as an example and make you own factory, which will create sockes already bound to your local address. This will work even with the older versions of Commons-Net.
        Hide
        Sebb added a comment -

        Thanks, patch applied with minor changes; also added method

        setPassiveLocalIPAddress(InetAddress inetAddress)

        for completeness

        Show
        Sebb added a comment - Thanks, patch applied with minor changes; also added method setPassiveLocalIPAddress(InetAddress inetAddress) for completeness
        Hide
        Sebb added a comment -

        URL: http://svn.apache.org/viewvc?rev=1359960&view=rev
        Log:
        NET-462 FTPClient in PASSIVE_LOCAL_DATA_CONNECTION_MODE cannot work when host have several different IP

        Modified:
        commons/proper/net/trunk/src/changes/changes.xml
        commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClient.java

        Show
        Sebb added a comment - URL: http://svn.apache.org/viewvc?rev=1359960&view=rev Log: NET-462 FTPClient in PASSIVE_LOCAL_DATA_CONNECTION_MODE cannot work when host have several different IP Modified: commons/proper/net/trunk/src/changes/changes.xml commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClient.java

          People

          • Assignee:
            Unassigned
            Reporter:
            Junsheng Chen
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 24h
              24h
              Remaining:
              Remaining Estimate - 24h
              24h
              Logged:
              Time Spent - Not Specified
              Not Specified

                Development