commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1228697 - in /commons/proper/net/trunk/src: changes/changes.xml main/java/org/apache/commons/net/ftp/FTPClient.java
Date Sat, 07 Jan 2012 18:38:45 GMT
Author: sebb
Date: Sat Jan  7 18:38:45 2012
New Revision: 1228697

URL: http://svn.apache.org/viewvc?rev=1228697&view=rev
Log:
NET-346 FTP should support reporting NATed external IP address

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

Modified: commons/proper/net/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/changes/changes.xml?rev=1228697&r1=1228696&r2=1228697&view=diff
==============================================================================
--- commons/proper/net/trunk/src/changes/changes.xml (original)
+++ commons/proper/net/trunk/src/changes/changes.xml Sat Jan  7 18:38:45 2012
@@ -59,6 +59,9 @@ The <action> type attribute can be add,u
         <release version="3.1-SNAPSHOT" date="TBA" description="
 TBA
         ">
+            <action issue="NET346" dev="sebb" type="add" due-to="Kevin Samuel">
+            FTP should support reporting NATed external IP address
+            </action>
             <action issue="NET-433" dev="sebb" type="add">
             NET site should link to the examples
             </action>

Modified: commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClient.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClient.java?rev=1228697&r1=1228696&r2=1228697&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClient.java (original)
+++ commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClient.java Sat Jan
 7 18:38:45 2012
@@ -334,6 +334,8 @@ implements Configurable
     private final Random __random;
     private int __activeMinPort, __activeMaxPort;
     private InetAddress __activeExternalHost;
+    private InetAddress __reportActiveExternalHost; // overrides __activeExternalHost in
EPRT/PORT commands
+
     private int __fileType;
     @SuppressWarnings("unused") // fields are written, but currently not read
     private int __fileFormat, __fileStructure, __fileTransferMode;
@@ -445,6 +447,7 @@ implements Configurable
         __passiveHost        = null;
         __passivePort        = -1;
         __activeExternalHost = null;
+        __reportActiveExternalHost = null;
         __activeMinPort = 0;
         __activeMaxPort = 0;
         __fileType           = FTP.ASCII_FILE_TYPE;
@@ -692,11 +695,11 @@ implements Configurable
                 // substitute IP addresses in the PORT command,
                 // but might not be able to recognize the EPRT command.
                 if (isInet6Address) {
-                    if (!FTPReply.isPositiveCompletion(eprt(getHostAddress(), server.getLocalPort())))
{
+                    if (!FTPReply.isPositiveCompletion(eprt(getReportHostAddress(), server.getLocalPort())))
{
                         return null;
                     }
                 } else {
-                    if (!FTPReply.isPositiveCompletion(port(getHostAddress(), server.getLocalPort())))
{
+                    if (!FTPReply.isPositiveCompletion(port(getReportHostAddress(), server.getLocalPort())))
{
                         return null;
                     }
                 }
@@ -1239,9 +1242,10 @@ implements Configurable
     }
 
     /**
-     * Get the host address for active mode.
+     * Get the host address for active mode; allows the local address to be overridden.
      * <p>
-     * @return The host address for active mode.
+     * @return __activeExternalHost if non-null, else getLocalAddress()
+     * @see #setActiveExternalIPAddress(String)
      */
     private InetAddress getHostAddress()
     {
@@ -1255,6 +1259,22 @@ implements Configurable
             return getLocalAddress();
         }
     }
+    
+    /**
+     * Get the reported host address for active mode EPRT/PORT commands;
+     * allows override of {@link #getHostAddress()}.
+     * 
+     * Useful for FTP Client behind Firewall NAT.
+     * <p>
+     * @return __reportActiveExternalHost if non-null, else getHostAddress();
+     */
+    private InetAddress getReportHostAddress() {
+        if (__reportActiveExternalHost != null) {
+            return __reportActiveExternalHost ;
+        } else {
+            return getHostAddress();
+        }
+    }
 
     /***
      * Set the client side port range in active mode.
@@ -1282,6 +1302,20 @@ implements Configurable
         this.__activeExternalHost = InetAddress.getByName(ipAddress);
     }
 
+    /**
+     * Set the external IP address to report in EPRT/PORT commands in active mode.
+     * Useful when there are multiple network cards.
+     * <p>
+     * @param ipAddress The external IP address of this machine.
+     * @throws UnknownHostException
+     * @since 3.1
+     * @see #getReportHostAddress()
+     */
+    public void setReportActiveExternalIPAddress(String ipAddress) throws UnknownHostException
+    {
+        this.__reportActiveExternalHost = InetAddress.getByName(ipAddress);
+    }
+
 
     /***
      * Sets the file type to be transferred.  This should be one of



Mime
View raw message