title: apache FTP Client connection timeout when connecting to remove host
body: <p>The tittle is duplicate but the question is different.</p>
  
  <p>I am using the FTPClient[apache commons 3.6] class to connect to an FTP Server[apache ftp server 1.1.1 jar file] which was launched by code. This FTP Server was configured as follows</p>
  
  <pre><code>  FtpServerFactory serverFactory = new FtpServerFactory();
  
    ListenerFactory factory = new ListenerFactory();
    factory.setServerAddress("/*IP Address*/");//The IPV4 Address Of My System
    factory.setPort(8001);  
    serverFactory.addListener("default",listener=factory.createListener());
  
     PropertiesUserManagerFactory userFactory=new PropertiesUserManagerFactory();
     userFactory.setPasswordEncryptor(new ClearTextPasswordEncryptor());
     BaseUser baseUser=new BaseUser();
     baseUser.setName("Test");
     baseUser.setPassword("123");
     baseUser.setEnabled(true);
     baseUser.setHomeDirectory("E:/Test Data");
     baseUser.setAuthorities(Arrays.asList(new WritePermission()));
     UserManager uManager=userFactory.createUserManager();
     serverFactory.setUserManager(uManager);      
  
    ftpServer=serverFactory.createServer();
    ftpServer.start();
  </code></pre>
  
  <p>And Here Is How I Connect To This Server</p>
  
  <pre><code>FTPClient client=new FTPClient();
  client.connect("/*Same IP Address As Server*/",8001);
  
  client.enterLocalPassiveMode();
  
  client.logIn("Test","123");
  </code></pre>
  
  <p>The Code works fine when both server and client are in the same system but when server is an remote host I get the "ConnectionTimedOutException" when im logging in</p>
  
  <pre><code>client.logIn("Test","123"); //It Throws Timeout here
  </code></pre>
  
  <p>Its odd that connect() works but timesout when logging in. Any parameters to tweek here?</p>
  
  <p>I tested the server with the FTPClient gui FileZela which gives me the same error when server is in remove system but works within the same system
  <a href="https://filezilla-project.org/download.php?type=client" rel="nofollow noreferrer">https://filezilla-project.org/download.php?type=client</a></p>
  
  <p>Here is the stack trace for my connection code</p>
  
  <pre><code>java.net.SocketTimeoutException: connect timed out
      at java.base/java.net.PlainSocketImpl.waitForConnect(Native Method)
      at java.base/java.net.PlainSocketImpl.socketConnect(PlainSocketImpl.java:107)
      at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:399)
      at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242)
      at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224)
      at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:403)
      at java.base/java.net.Socket.connect(Socket.java:591)
      at org.apache.commons.net.SocketClient._connect(SocketClient.java:243)
      at org.apache.commons.net.SocketClient.connect(SocketClient.java:202)
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>I tweeked  some parameters and now I am able to login to my remote server I had To change the following parameters</p>
  
  <pre><code> client.setSoTimeout(5000);   //Time To Wait For Login Operation(in milliseconds)
   client.setControlKeepAliveTimeout(1); //Time Interval to send keep alive messages(in seconds)
   client.setControlKeepAliveReplyTimeout(5000);// Time to wait for an keep alive response message (in milliseconds)
  </code></pre>
  
  <p>But now my connection times out when uploading any data for example</p>
  
  <pre><code> try(OutputStream toFile=client.storeFileStream("File.txt"))
   {
    toFile.write("Just Some Small Text".getBytes());
    toFile.close();
   }
  
   if(!FTPReply.isPositiveCompletion(client.getReplyCode()))
   {
    String[] replies = ftpClient.getReplyStrings();
    if (replies != null &amp;&amp; replies.length &gt; 0) 
    {
     StringBuilder builder=new StringBuilder();
     for(String aReply : replies){builder.append(aReply).append(" ");}
     JOptionPane.showMessageDialog(null,builder.toString());
    } 
  
    //The server replies here are connection timeout no exception is thrown 
   }
  </code></pre>