title: Why FTPConnectionClosedException is thrown for a folder with 170K files over FTP?
body: <p>I am trying to rename the files over FTP using commons net FTP 3.5 and Java  1.8.0.45. There is one specific folder with 170K small files (25 GB) in it. Whenever I try to list this folder, it returns below exception. For rest of folders, it runs fine and renaming the files.</p>
  
  <pre><code>org.apache.commons.net.ftp.FTPConnectionClosedException: Connection closed without indication.
      at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:316)
      at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:292)
      at org.apache.commons.net.ftp.FTP.getReply(FTP.java:712)
      at org.apache.commons.net.ftp.FTPClient.completePendingCommand(FTPClient.java:1857)
      at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:3420)
      at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:3335)
      at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:3012)
      at TestFTP.execute(TestFTP.java:27)
      at TestFTP.main(TestFTP.java:12)
  org.apache.commons.net.ftp.FTPConnectionClosedException: Connection closed without indication.
      at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:316)
      at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:292)
      at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:503)
      at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:628)
      at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:602)
      at org.apache.commons.net.ftp.FTP.quit(FTP.java:884)
      at org.apache.commons.net.ftp.FTPClient.logout(FTPClient.java:1152)
      at TestFTP.execute(TestFTP.java:62)
      at TestFTP.main(TestFTP.java:12)
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>import java.io.IOException;
  import java.text.DateFormat;
  import java.text.SimpleDateFormat;
  
  import org.apache.commons.net.ftp.FTPClient;
  import org.apache.commons.net.ftp.FTPFile;
  
  public class TestFTP {
      public static void main(String[] args) {
          TestFTP.execute(args[0], args[1]);
      }
      static DateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      public static void execute(String ip, String folder) {
          String server = ip;
          int port = 21;
          String user = "adminuser";
          String pass = "adminuser";
  
          long start = System.currentTimeMillis();
          FTPClient ftpClient = new FTPClient();
          try {
              ftpClient.connect(server, port);
              ftpClient.login(user, pass);
  
              FTPFile[] files = ftpClient.listFiles(folder);
              for (FTPFile file : files) {
                  String details = file.getName();
  
                  // renaming file
                  String oldFile = folder + file.getName();
                  String newFile = folder + "_X_" + file.getName();
  
                  boolean success = ftpClient.rename(oldFile, newFile);
                  if (success) {
                      System.out.println(oldFile + " was successfully renamed to: "
                              + newFile);
                  } else {
                      System.out.println("Failed to rename: " + oldFile);
                  }
              }
  
              ftpClient.logout();
              ftpClient.disconnect();
  
              long end = System.currentTimeMillis();
              System.out.println("time:"  +(end-start));
  
          } catch (IOException ex) {
              ex.printStackTrace();
          } finally {
              if (ftpClient.isConnected()) {
                  try {
                      ftpClient.logout();
                      ftpClient.disconnect();
                  } catch (IOException ex) {
                      ex.printStackTrace();
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>Is there any way to make my FTP server to respond request to list such a large folder like increasing timeout ? or Do I miss something ? Thanks in advance !</p>