You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "daniel damon (JIRA)" <ji...@apache.org> on 2011/03/04 23:40:45 UTC

[jira] Commented: (NET-296) java.net.SocketException: Operation timed out error while entering Passive mode

    [ https://issues.apache.org/jira/browse/NET-296?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13002854#comment-13002854 ] 

daniel damon commented on NET-296:
----------------------------------

I am also seeing the problem.  While I can get a connection, I cannot transfer data. I can use a commercial offering to do so.

I believe the problem occurs when the FTP server is behind a firewall. When it responds to the PASV command, it gives it's address, not the firewall address.

If the FTPClient responds to that address, of course it will fail. 

Something like this probably needs to happen: The FTPClient tries to open at the given address.  If it does not work, try the original address with the given port.

> java.net.SocketException: Operation timed out error while entering Passive mode
> -------------------------------------------------------------------------------
>
>                 Key: NET-296
>                 URL: https://issues.apache.org/jira/browse/NET-296
>             Project: Commons Net
>          Issue Type: Bug
>    Affects Versions: 2.0
>         Environment: Windows XP, JDK 1.5.0_15, commons-net-2.0-jdk14.jar
>            Reporter: Hariprasad K S
>            Priority: Blocker
>
> Hi,
> I am getting the following error while trying to connect to the FTP (Explicit).
> java.net.SocketException: Operation timed out: connect:could be due to invalid address.
> I am facing this error when i am running the code from the client machine which is in different domain...If i run the same code in the domain where ftp exists..it works fine without any issue...below is my code and the trace log....Pls help.
> FTPSClient client = new FTPSClient("TLS",false);
> 	client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
> 	boolean _ftp_login = false;
>          
>         try {
>             String[] hname = ftpurl.split("//");
>             client.setAuthValue("TLS");
>             client.setRemoteVerificationEnabled(false);
> 	    client.connect("ftp.kotaklifeinsurance.com",22);
>              
>             int reply = client.getReplyCode();
>             client.execPBSZ(0);            
>             client.execPROT("P");
>             
>             if (!FTPReply.isPositiveCompletion(reply)) {
>                 client.disconnect();
>                 System.out.println("openFTPClient(): FTP server refused connection.");
>                 throw new Exception("FTP server refused connection.");
>             } else {
>                 try {
>                     _ftp_login = client.login(userID, password);
>                 } catch (Exception e) {
>                     throw e;
>                 }
>                 if (_ftp_login) {
>                  
>                     client.enterLocalPassiveMode();
>                     
>                     if (client.printWorkingDirectory() == null)
>                         throw new Exception("Current working directory returned is null");
>                     client.changeWorkingDirectory("/XYZ/");
> 		    fis = new FileInputStream(localfile);
>   		    ins = (InputStream)fis;
> 		    boolean flag = client.storeFile(filename,ins);
> 		    System.out.println("File saved to FTP : "+flag);
> Error Trace : 
> 220 Unauthorized Access Prohibited.
> AUTH TLS
> 234 AUTH command ok. Expecting TLS Negotiation.
> PBSZ 0
> 200 PBSZ command successful.
> PROT P
> 200 PROT command successful.
> USER userid
> 331 Password required for userid.
> PASS password
> 230 User logged in.
> PWD
> 257 "/" is current directory.
> CWD /XYZ/
> 250 CWD command successful.
> PWD
> 257 "/XYZ" is current directory.
> TYPE A
> 200 Type set to A.
> MODE I
> 501 'MODE I': parameter not understood.
> STRU F
> 200 STRU F ok.
> PASV
> 227 Entering Passive Mode (192,168,201,220,195,108).
> java.net.SocketException: Operation timed out: connect:could be due to invalid address
> 	at java.net.PlainSocketImpl.socketConnect(Native Method)
> 	at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:331)
> 	at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:196)
> 	at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:183)
> 	at java.net.Socket.connect(Socket.java:478)
> 	at java.net.Socket.connect(Socket.java:428)
> 	at java.net.Socket.<init>(Socket.java:335)
> 	at java.net.Socket.<init>(Socket.java:150)
> 	at com.ibm.jsse.bs.<init>(Unknown Source)
> 	at com.ibm.jsse.JSSESocketFactory.createSocket(Unknown Source)
> 	at org.apache.commons.net.ftp.FTPSSocketFactory.createSocket(FTPSSocketFactory.java:48)
> 	at org.apache.commons.net.ftp.FTPClient._openDataConnection_(FTPClient.java:502)
> 	at org.apache.commons.net.ftp.FTPSClient._openDataConnection_(FTPSClient.java:494)
> 	at org.apache.commons.net.ftp.FTPClient.__storeFile(FTPClient.java:374)
> 	at org.apache.commons.net.ftp.FTPClient.storeFile(FTPClient.java:1379)

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