You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Kevin Samuel (JIRA)" <ji...@apache.org> on 2010/12/15 09:51:01 UTC

[jira] Created: (NET-346) FTP should support reporting NATed external IP address

FTP should support reporting NATed external IP address
------------------------------------------------------

                 Key: NET-346
                 URL: https://issues.apache.org/jira/browse/NET-346
             Project: Commons Net
          Issue Type: Improvement
          Components: FTP
    Affects Versions: 2.2
            Reporter: Kevin Samuel


When trying to do an active FTP transfer as client from behind a firewall with NAT, setActiveExternalIPAddress is not sufficient, as you can only report the internal IP of the client (e.g. 192.168.1.2 vs 72.14.X.X)

FTPClient should support an additional function to set the REPORTABLE external active IP Address

I created and successfully tested a fix for this:

ADD PRIVATE MEMBER:
private InetAddress __reportActiveExternalHost;

IN __initDefaults():
__reportActiveExternalHost = null;

ADD PUBLIC FUNCTIONS:
private InetAddress getReportHostAddress()
    {
    	if (__reportActiveExternalHost != null)
    	{
    		return __reportActiveExternalHost ;
    	}
    	else if (__activeExternalHost != null)
        {
            return __activeExternalHost;
        }
        else
        {
            // default local address
            return getLocalAddress();
        }
    }

public void setReportActiveExternalIPAddress(String ipAddress) throws UnknownHostException
    {
        this.__reportActiveExternalHost = InetAddress.getByName(ipAddress);
    }

IN _openDataConnection_:

if (isInet6Address)
            {
                if (!FTPReply.isPositiveCompletion(eprt(getReportHostAddress(), server.getLocalPort())))
                {
                    server.close();
                    return null;
                }
            }
            else
            {
                if (!FTPReply.isPositiveCompletion(port(getReportHostAddress(), server.getLocalPort())))
                {
                    server.close();
                    return null;
                }
            }


will also attach changed file

sorry I am not familiar with the correct way to submit patches, although I tried to model this on #NET-285 as much as possible



-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] [Commented] (NET-346) FTP should support reporting NATed external IP address

Posted by "Keigo Tanaka (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/NET-346?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13105108#comment-13105108 ] 

Keigo Tanaka commented on NET-346:
----------------------------------

According to HEAD of FTPClient.java(rev 1126692), when _openDataConnection_() called, it tries to open socket with createServerSocket on line 648, and it causes java.net.BindException.
setActiveExternalIPAddress() set the address for PORT command, however, the address is also used for binding the actual socket in _openDataConnection_().
This causes the problem when the client is inside of NAT.
When using NAT, the gateway has a global IP address, and the client has a private IP address.
The Exception from setActiveExternalIPAddress is caused by the mismatch of the global IP address and the private IP address.
Because the client host does not have the global IP address as the local address, the client will fail to bind the address.
I believe this patch is useful for such situation. Please merge it into the HEAD branch.

> FTP should support reporting NATed external IP address
> ------------------------------------------------------
>
>                 Key: NET-346
>                 URL: https://issues.apache.org/jira/browse/NET-346
>             Project: Commons Net
>          Issue Type: Improvement
>          Components: FTP
>    Affects Versions: 2.2
>            Reporter: Kevin Samuel
>         Attachments: FTPClient.java, ftpclient.patch
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> When trying to do an active FTP transfer as client from behind a firewall with NAT, setActiveExternalIPAddress is not sufficient, as you can only report the internal IP of the client (e.g. 192.168.1.2 vs 72.14.X.X)
> FTPClient should support an additional function to set the REPORTABLE external active IP Address
> I created and successfully tested a fix for this:
> ADD PRIVATE MEMBER:
> private InetAddress __reportActiveExternalHost;
> IN __initDefaults():
> __reportActiveExternalHost = null;
> ADD PUBLIC FUNCTIONS:
> private InetAddress getReportHostAddress()
>     {
>     	if (__reportActiveExternalHost != null)
>     	{
>     		return __reportActiveExternalHost ;
>     	}
>     	else if (__activeExternalHost != null)
>         {
>             return __activeExternalHost;
>         }
>         else
>         {
>             // default local address
>             return getLocalAddress();
>         }
>     }
> public void setReportActiveExternalIPAddress(String ipAddress) throws UnknownHostException
>     {
>         this.__reportActiveExternalHost = InetAddress.getByName(ipAddress);
>     }
> IN _openDataConnection_:
> if (isInet6Address)
>             {
>                 if (!FTPReply.isPositiveCompletion(eprt(getReportHostAddress(), server.getLocalPort())))
>                 {
>                     server.close();
>                     return null;
>                 }
>             }
>             else
>             {
>                 if (!FTPReply.isPositiveCompletion(port(getReportHostAddress(), server.getLocalPort())))
>                 {
>                     server.close();
>                     return null;
>                 }
>             }
> will also attach changed file
> sorry I am not familiar with the correct way to submit patches, although I tried to model this on #NET-285 as much as possible

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Resolved] (NET-346) FTP should support reporting NATed external IP address

Posted by "Sebb (Resolved) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/NET-346?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sebb resolved NET-346.
----------------------

       Resolution: Fixed
    Fix Version/s: 3.1

Applied, with a minor change: getReportHostAddress now defers to getHostAddress if __reportActiveExternalHost is null.
                
> FTP should support reporting NATed external IP address
> ------------------------------------------------------
>
>                 Key: NET-346
>                 URL: https://issues.apache.org/jira/browse/NET-346
>             Project: Commons Net
>          Issue Type: Improvement
>          Components: FTP
>    Affects Versions: 2.2
>            Reporter: Kevin Samuel
>             Fix For: 3.1
>
>         Attachments: FTPClient.java, ftpclient.patch
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> When trying to do an active FTP transfer as client from behind a firewall with NAT, setActiveExternalIPAddress is not sufficient, as you can only report the internal IP of the client (e.g. 192.168.1.2 vs 72.14.X.X)
> FTPClient should support an additional function to set the REPORTABLE external active IP Address
> I created and successfully tested a fix for this:
> ADD PRIVATE MEMBER:
> private InetAddress __reportActiveExternalHost;
> IN __initDefaults():
> __reportActiveExternalHost = null;
> ADD PUBLIC FUNCTIONS:
> private InetAddress getReportHostAddress()
>     {
>     	if (__reportActiveExternalHost != null)
>     	{
>     		return __reportActiveExternalHost ;
>     	}
>     	else if (__activeExternalHost != null)
>         {
>             return __activeExternalHost;
>         }
>         else
>         {
>             // default local address
>             return getLocalAddress();
>         }
>     }
> public void setReportActiveExternalIPAddress(String ipAddress) throws UnknownHostException
>     {
>         this.__reportActiveExternalHost = InetAddress.getByName(ipAddress);
>     }
> IN _openDataConnection_:
> if (isInet6Address)
>             {
>                 if (!FTPReply.isPositiveCompletion(eprt(getReportHostAddress(), server.getLocalPort())))
>                 {
>                     server.close();
>                     return null;
>                 }
>             }
>             else
>             {
>                 if (!FTPReply.isPositiveCompletion(port(getReportHostAddress(), server.getLocalPort())))
>                 {
>                     server.close();
>                     return null;
>                 }
>             }
> will also attach changed file
> sorry I am not familiar with the correct way to submit patches, although I tried to model this on #NET-285 as much as possible

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Updated: (NET-346) FTP should support reporting NATed external IP address

Posted by "Kevin Samuel (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/NET-346?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Kevin Samuel updated NET-346:
-----------------------------

    Attachment: FTPClient.java

again sorry  this is not a proper patch file

> FTP should support reporting NATed external IP address
> ------------------------------------------------------
>
>                 Key: NET-346
>                 URL: https://issues.apache.org/jira/browse/NET-346
>             Project: Commons Net
>          Issue Type: Improvement
>          Components: FTP
>    Affects Versions: 2.2
>            Reporter: Kevin Samuel
>         Attachments: FTPClient.java
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> When trying to do an active FTP transfer as client from behind a firewall with NAT, setActiveExternalIPAddress is not sufficient, as you can only report the internal IP of the client (e.g. 192.168.1.2 vs 72.14.X.X)
> FTPClient should support an additional function to set the REPORTABLE external active IP Address
> I created and successfully tested a fix for this:
> ADD PRIVATE MEMBER:
> private InetAddress __reportActiveExternalHost;
> IN __initDefaults():
> __reportActiveExternalHost = null;
> ADD PUBLIC FUNCTIONS:
> private InetAddress getReportHostAddress()
>     {
>     	if (__reportActiveExternalHost != null)
>     	{
>     		return __reportActiveExternalHost ;
>     	}
>     	else if (__activeExternalHost != null)
>         {
>             return __activeExternalHost;
>         }
>         else
>         {
>             // default local address
>             return getLocalAddress();
>         }
>     }
> public void setReportActiveExternalIPAddress(String ipAddress) throws UnknownHostException
>     {
>         this.__reportActiveExternalHost = InetAddress.getByName(ipAddress);
>     }
> IN _openDataConnection_:
> if (isInet6Address)
>             {
>                 if (!FTPReply.isPositiveCompletion(eprt(getReportHostAddress(), server.getLocalPort())))
>                 {
>                     server.close();
>                     return null;
>                 }
>             }
>             else
>             {
>                 if (!FTPReply.isPositiveCompletion(port(getReportHostAddress(), server.getLocalPort())))
>                 {
>                     server.close();
>                     return null;
>                 }
>             }
> will also attach changed file
> sorry I am not familiar with the correct way to submit patches, although I tried to model this on #NET-285 as much as possible

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] [Updated] (NET-346) FTP should support reporting NATed external IP address

Posted by "Sebb (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/NET-346?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sebb updated NET-346:
---------------------

    Attachment: ftpclient.patch

For reference: diff between patch and NET 2.2 versions of FTPClient.java

> FTP should support reporting NATed external IP address
> ------------------------------------------------------
>
>                 Key: NET-346
>                 URL: https://issues.apache.org/jira/browse/NET-346
>             Project: Commons Net
>          Issue Type: Improvement
>          Components: FTP
>    Affects Versions: 2.2
>            Reporter: Kevin Samuel
>         Attachments: FTPClient.java, ftpclient.patch
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> When trying to do an active FTP transfer as client from behind a firewall with NAT, setActiveExternalIPAddress is not sufficient, as you can only report the internal IP of the client (e.g. 192.168.1.2 vs 72.14.X.X)
> FTPClient should support an additional function to set the REPORTABLE external active IP Address
> I created and successfully tested a fix for this:
> ADD PRIVATE MEMBER:
> private InetAddress __reportActiveExternalHost;
> IN __initDefaults():
> __reportActiveExternalHost = null;
> ADD PUBLIC FUNCTIONS:
> private InetAddress getReportHostAddress()
>     {
>     	if (__reportActiveExternalHost != null)
>     	{
>     		return __reportActiveExternalHost ;
>     	}
>     	else if (__activeExternalHost != null)
>         {
>             return __activeExternalHost;
>         }
>         else
>         {
>             // default local address
>             return getLocalAddress();
>         }
>     }
> public void setReportActiveExternalIPAddress(String ipAddress) throws UnknownHostException
>     {
>         this.__reportActiveExternalHost = InetAddress.getByName(ipAddress);
>     }
> IN _openDataConnection_:
> if (isInet6Address)
>             {
>                 if (!FTPReply.isPositiveCompletion(eprt(getReportHostAddress(), server.getLocalPort())))
>                 {
>                     server.close();
>                     return null;
>                 }
>             }
>             else
>             {
>                 if (!FTPReply.isPositiveCompletion(port(getReportHostAddress(), server.getLocalPort())))
>                 {
>                     server.close();
>                     return null;
>                 }
>             }
> will also attach changed file
> sorry I am not familiar with the correct way to submit patches, although I tried to model this on #NET-285 as much as possible

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] Issue Comment Edited: (NET-346) FTP should support reporting NATed external IP address

Posted by "Kevin Samuel (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/NET-346?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12971582#action_12971582 ] 

Kevin Samuel edited comment on NET-346 at 12/15/10 4:03 AM:
------------------------------------------------------------

*test code:*

			boolean rc = false;
			
			String localFile = "test.txt";
			String remoteFile = "test.txt";

			FTPClient ftp = new FTPClient();
						
			ftp.connect( ftpServer );
			
			ftp.setActiveExternalIPAddress("192.168.1.5");
			*ftp.setReportActiveExternalIPAddress("X.X.X.X");*
			ftp.setActivePortRange(6000, 7000);
			
			rc = ftp.login( ftpUser , ftpPass );
			if(!rc){ftp.disconnect();return;}
			
			rc = ftp.retrieveFile(remoteFile,new FileOutputStream(new File(localFile)));
			if(!rc){ftp.disconnect();return;}


      was (Author: ksamuel):
    *test code:*

			boolean rc = false;
			
			String localFile = "test.txt";
			String remoteFile = "test.txt";

			FTPClient ftp = new FTPClient();
						
			ftp.connect( ftpServer );
			
			ftp.setActiveExternalIPAddress("192.168.1.5");
			*ftp.setReportActiveExternalIPAddress("X.X.X.X");*
			ftp.setActivePortRange(6000, 7000);
			
			rc = ftp.login( ftpUser , ftpPass );
			if(!rc){ftp.disconnect();return;}

			ftp.changeWorkingDirectory(remoteDir);
			if(!rc){ftp.disconnect();return;}
			
			Log.info("    FTP GET : " + remoteFile + " >> " + localFile);
			rc = ftp.retrieveFile(remoteFile,new FileOutputStream(new File(localFile)));
			if(!rc){ftp.disconnect();return;}

  
> FTP should support reporting NATed external IP address
> ------------------------------------------------------
>
>                 Key: NET-346
>                 URL: https://issues.apache.org/jira/browse/NET-346
>             Project: Commons Net
>          Issue Type: Improvement
>          Components: FTP
>    Affects Versions: 2.2
>            Reporter: Kevin Samuel
>         Attachments: FTPClient.java
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> When trying to do an active FTP transfer as client from behind a firewall with NAT, setActiveExternalIPAddress is not sufficient, as you can only report the internal IP of the client (e.g. 192.168.1.2 vs 72.14.X.X)
> FTPClient should support an additional function to set the REPORTABLE external active IP Address
> I created and successfully tested a fix for this:
> ADD PRIVATE MEMBER:
> private InetAddress __reportActiveExternalHost;
> IN __initDefaults():
> __reportActiveExternalHost = null;
> ADD PUBLIC FUNCTIONS:
> private InetAddress getReportHostAddress()
>     {
>     	if (__reportActiveExternalHost != null)
>     	{
>     		return __reportActiveExternalHost ;
>     	}
>     	else if (__activeExternalHost != null)
>         {
>             return __activeExternalHost;
>         }
>         else
>         {
>             // default local address
>             return getLocalAddress();
>         }
>     }
> public void setReportActiveExternalIPAddress(String ipAddress) throws UnknownHostException
>     {
>         this.__reportActiveExternalHost = InetAddress.getByName(ipAddress);
>     }
> IN _openDataConnection_:
> if (isInet6Address)
>             {
>                 if (!FTPReply.isPositiveCompletion(eprt(getReportHostAddress(), server.getLocalPort())))
>                 {
>                     server.close();
>                     return null;
>                 }
>             }
>             else
>             {
>                 if (!FTPReply.isPositiveCompletion(port(getReportHostAddress(), server.getLocalPort())))
>                 {
>                     server.close();
>                     return null;
>                 }
>             }
> will also attach changed file
> sorry I am not familiar with the correct way to submit patches, although I tried to model this on #NET-285 as much as possible

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (NET-346) FTP should support reporting NATed external IP address

Posted by "Kevin Samuel (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/NET-346?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12971582#action_12971582 ] 

Kevin Samuel commented on NET-346:
----------------------------------

*test code:*

			boolean rc = false;
			
			String localFile = "test.txt";
			String remoteFile = "test.txt";

			FTPClient ftp = new FTPClient();
						
			ftp.connect( ftpServer );
			
			ftp.setActiveExternalIPAddress("192.168.1.5");
			*ftp.setReportActiveExternalIPAddress("X.X.X.X");*
			ftp.setActivePortRange(6000, 7000);
			
			rc = ftp.login( ftpUser , ftpPass );
			if(!rc){ftp.disconnect();return;}

			ftp.changeWorkingDirectory(remoteDir);
			if(!rc){ftp.disconnect();return;}
			
			Log.info("    FTP GET : " + remoteFile + " >> " + localFile);
			rc = ftp.retrieveFile(remoteFile,new FileOutputStream(new File(localFile)));
			if(!rc){ftp.disconnect();return;}


> FTP should support reporting NATed external IP address
> ------------------------------------------------------
>
>                 Key: NET-346
>                 URL: https://issues.apache.org/jira/browse/NET-346
>             Project: Commons Net
>          Issue Type: Improvement
>          Components: FTP
>    Affects Versions: 2.2
>            Reporter: Kevin Samuel
>         Attachments: FTPClient.java
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> When trying to do an active FTP transfer as client from behind a firewall with NAT, setActiveExternalIPAddress is not sufficient, as you can only report the internal IP of the client (e.g. 192.168.1.2 vs 72.14.X.X)
> FTPClient should support an additional function to set the REPORTABLE external active IP Address
> I created and successfully tested a fix for this:
> ADD PRIVATE MEMBER:
> private InetAddress __reportActiveExternalHost;
> IN __initDefaults():
> __reportActiveExternalHost = null;
> ADD PUBLIC FUNCTIONS:
> private InetAddress getReportHostAddress()
>     {
>     	if (__reportActiveExternalHost != null)
>     	{
>     		return __reportActiveExternalHost ;
>     	}
>     	else if (__activeExternalHost != null)
>         {
>             return __activeExternalHost;
>         }
>         else
>         {
>             // default local address
>             return getLocalAddress();
>         }
>     }
> public void setReportActiveExternalIPAddress(String ipAddress) throws UnknownHostException
>     {
>         this.__reportActiveExternalHost = InetAddress.getByName(ipAddress);
>     }
> IN _openDataConnection_:
> if (isInet6Address)
>             {
>                 if (!FTPReply.isPositiveCompletion(eprt(getReportHostAddress(), server.getLocalPort())))
>                 {
>                     server.close();
>                     return null;
>                 }
>             }
>             else
>             {
>                 if (!FTPReply.isPositiveCompletion(port(getReportHostAddress(), server.getLocalPort())))
>                 {
>                     server.close();
>                     return null;
>                 }
>             }
> will also attach changed file
> sorry I am not familiar with the correct way to submit patches, although I tried to model this on #NET-285 as much as possible

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] [Commented] (NET-346) FTP should support reporting NATed external IP address

Posted by "Sebb (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/NET-346?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13009538#comment-13009538 ] 

Sebb commented on NET-346:
--------------------------

What happens if you use

{code}
ftp.setActiveExternalIPAddress("X.X.X.X");
{code}

Does that not work?

> FTP should support reporting NATed external IP address
> ------------------------------------------------------
>
>                 Key: NET-346
>                 URL: https://issues.apache.org/jira/browse/NET-346
>             Project: Commons Net
>          Issue Type: Improvement
>          Components: FTP
>    Affects Versions: 2.2
>            Reporter: Kevin Samuel
>         Attachments: FTPClient.java
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> When trying to do an active FTP transfer as client from behind a firewall with NAT, setActiveExternalIPAddress is not sufficient, as you can only report the internal IP of the client (e.g. 192.168.1.2 vs 72.14.X.X)
> FTPClient should support an additional function to set the REPORTABLE external active IP Address
> I created and successfully tested a fix for this:
> ADD PRIVATE MEMBER:
> private InetAddress __reportActiveExternalHost;
> IN __initDefaults():
> __reportActiveExternalHost = null;
> ADD PUBLIC FUNCTIONS:
> private InetAddress getReportHostAddress()
>     {
>     	if (__reportActiveExternalHost != null)
>     	{
>     		return __reportActiveExternalHost ;
>     	}
>     	else if (__activeExternalHost != null)
>         {
>             return __activeExternalHost;
>         }
>         else
>         {
>             // default local address
>             return getLocalAddress();
>         }
>     }
> public void setReportActiveExternalIPAddress(String ipAddress) throws UnknownHostException
>     {
>         this.__reportActiveExternalHost = InetAddress.getByName(ipAddress);
>     }
> IN _openDataConnection_:
> if (isInet6Address)
>             {
>                 if (!FTPReply.isPositiveCompletion(eprt(getReportHostAddress(), server.getLocalPort())))
>                 {
>                     server.close();
>                     return null;
>                 }
>             }
>             else
>             {
>                 if (!FTPReply.isPositiveCompletion(port(getReportHostAddress(), server.getLocalPort())))
>                 {
>                     server.close();
>                     return null;
>                 }
>             }
> will also attach changed file
> sorry I am not familiar with the correct way to submit patches, although I tried to model this on #NET-285 as much as possible

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira