title: Recursively list files and directories in an FTP server using Java
body: <p>I'm currently using a Java FTP library (ftp4j) to access a FTP server. I want to do a file count and directory count for the server, but this means I would need to list files within directories within directories within directories, etc.</p>
  
  <p>How is this achievable? Any hints would be greatly appreciated.</p>
  
  <p>Extract from the code:</p>
  
  <pre><code>client = new FTPClient();
  try {
      client.connect("");
      client.login("", "");
      client.changeDirectory("/");
      FTPFile[] list = client.list();
      int totalDIRS = 0;
      int totalFILES = 0;
      for (FTPFile ftpFile : list) {
          if (ftpFile.getType() == FTPFile.TYPE_DIRECTORY) {
              totalDIRS++;
          }
      }
      message =
          "There are currently " + totalDIRS + " directories within the ROOT directory";
      client.disconnect(true);
  } catch (Exception e) {
      System.out.println(e.toString());
  }
  </code></pre>