You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2013/04/17 21:45:05 UTC
svn commit: r1469044 - in /commons/proper/net/trunk/src: changes/changes.xml
main/java/org/apache/commons/net/ftp/FTPClient.java
Author: sebb
Date: Wed Apr 17 19:45:05 2013
New Revision: 1469044
URL: http://svn.apache.org/r1469044
Log:
NET-507 Option to disable private IP replacement in FTP passive mode.
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=1469044&r1=1469043&r2=1469044&view=diff
==============================================================================
--- commons/proper/net/trunk/src/changes/changes.xml (original)
+++ commons/proper/net/trunk/src/changes/changes.xml Wed Apr 17 19:45:05 2013
@@ -64,6 +64,9 @@ The <action> type attribute can be add,u
<body>
<release version="3.3" date="TBA" description="
">
+ <action issue="NET-507" dev="sebb" type="update">
+ Option to disable private IP replacement in FTP passive mode.
+ </action>
<action issue="NET-503" dev="sebb" type="add">
AuthenticatingSMTPClient does not support non-default encoding
</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=1469044&r1=1469043&r2=1469044&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 Wed Apr 17 19:45:05 2013
@@ -390,6 +390,11 @@ implements Configurable
// Most FTP servers don't seem to support concurrent control and data connection usage
private int __controlKeepAliveReplyTimeout=1000;
+ /**
+ * Enable or disable replacement of internal IP in passive mode. Default enabled.
+ */
+ private boolean __passiveNatWorkaround = true;
+
/** Pattern for PASV mode responses. Groups: (n,n,n,n),(n),(n) */
private static final java.util.regex.Pattern __PARMS_PAT;
static {
@@ -559,21 +564,23 @@ implements Configurable
"Could not parse passive port information.\nServer Reply: " + reply);
}
- try {
- InetAddress host = InetAddress.getByName(__passiveHost);
- // reply is a local address, but target is not - assume NAT box changed the PASV reply
- if (host.isSiteLocalAddress()) {
- InetAddress remote = getRemoteAddress();
- if (!remote.isSiteLocalAddress()){
- String hostAddress = remote.getHostAddress();
- fireReplyReceived(0,
- "[Replacing site local address "+__passiveHost+" with "+hostAddress+"]\n");
- __passiveHost = hostAddress;
+ if (__passiveNatWorkaround) {
+ try {
+ InetAddress host = InetAddress.getByName(__passiveHost);
+ // reply is a local address, but target is not - assume NAT box changed the PASV reply
+ if (host.isSiteLocalAddress()) {
+ InetAddress remote = getRemoteAddress();
+ if (!remote.isSiteLocalAddress()){
+ String hostAddress = remote.getHostAddress();
+ fireReplyReceived(0,
+ "[Replacing site local address "+__passiveHost+" with "+hostAddress+"]\n");
+ __passiveHost = hostAddress;
+ }
}
+ } catch (UnknownHostException e) { // Should not happen as we are passing in an IP address
+ throw new MalformedServerReplyException(
+ "Could not parse passive host information.\nServer Reply: " + reply);
}
- } catch (UnknownHostException e) { // Should not happen as we are passing in an IP address
- throw new MalformedServerReplyException(
- "Could not parse passive host information.\nServer Reply: " + reply);
}
}
@@ -3621,6 +3628,22 @@ implements Configurable
return __controlKeepAliveReplyTimeout;
}
+ /**
+ * Enable or disable passive mode NAT workaround.
+ * If enabled, a site-local PASV mode reply address will be replaced with the
+ * remote host address to which the PASV mode request was sent
+ * (unless that is also a site local address).
+ * This gets around the problem that some NAT boxes may change the
+ * reply.
+ *
+ * The default is true, i.e. site-local replies are replaced.
+ * @param enabled true to enable replacing internal IP's in passive
+ * mode.
+ */
+ public void setPassiveNatWorkaround(boolean enabled) {
+ this.__passiveNatWorkaround = enabled;
+ }
+
private OutputStream getBufferedOutputStream(OutputStream outputStream) {
if (__bufferSize > 0) {
return new BufferedOutputStream(outputStream, __bufferSize);