Hi,
   
  I am using FTPClient to put file in remote servers.  The code works fine in 
the local server(inside of my company), but always got time out problem in the 
outside server(client's FTP server).  I manually used command line ftp to the 
outside server without any problem. I searched on the web and found the 
setDefaultTimeout does not work and need create my own SocketFactory to set the 
connection time.  But I got the same result.  It does not work on my client's 
server.  Did anyone see this problem before?
   
  Thanks,
  Shawn
   
  Below is the error messages and code.
   
  java.net.ConnectException: Connection timed out: connect
 at java.net.PlainSocketImpl.socketConnect(Native Method)
 at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
 at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
 at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
 at java.net.Socket.connect(Socket.java:461)
 at applications.MySocketFactory.createSocket(MySocketFactory.java:29)
 at 
org.apache.commons.net.ftp.FTPClient._openDataConnection_(FTPClient.java:513)
 at org.apache.commons.net.ftp.FTPClient.__storeFile(FTPClient.java:388)
 at org.apache.commons.net.ftp.FTPClient.storeFile(FTPClient.java:1388)
  at util.FTPandSave.ftpPut(FTPandSave.java:87)
   
  My code:
  boolean success = false;
  FTPClient ftpClient = new FTPClient();
  ftpClient.setRemoteVerificationEnabled(false);
  
  // connect
  try 
  {
  MySocketFactory MySocketFactory = new MySocketFactory();
  MySocketFactory.setConnectTimeout(60000000);
  ftpClient.setSocketFactory(MySocketFactory);
  
  ftpClient.connect(aServer);
  ftpClient.login(aID,aPWD);
  ftpClient.enterLocalPassiveMode();
  ftpClient.setFileType(FTP.ASCII_FILE_TYPE);
  InputStream in1 = new FileInputStream(aFile);
  
    
success = ftpClient.storeFile(aFile.getName(), in1);
  } 
  catch (Exception e) 
  {
  LOG.error(e.getMessage(), e);
  return success;
  }

       
---------------------------------
Be a better friend, newshound, and know-it-all with Yahoo! Mobile.  Try it now.

Reply via email to