title: Apache Commons Net FTPClient Will Not Execute listFiles()
body: <p>I'm modifying some code that was previously working with an FTPS library I wrote myself. I've been asked to start using the Apache Commons Net library (FTPClient and FTPSClient mainly) and I'm running into problems doing a file listing. I've read other questions and it's not the enterLocalPassiveMode problem (<a href="https://stackoverflow.com/questions/2712967/apache-commons-net-ftpclient-and-listfiles">Apache Commons Net FTPClient and listFiles()</a>), as I'm using that after connecting, but before logging in. The same code works fine on a test server I set up (also using Apache FTP), but doesn't work on the server I need it for.</p>
  
  <p>I've also tried using the "PBSZ 0" and "PROT P" commands, but they're not implemented on the remote system.</p>
  
  <pre><code>502 PBSZ Command not implemented.
  502 PROT Command not implemented.
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>FTPSClient ftpsclient = new FTPSClient(true); // Implicit SSL
  ftpsclient.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out), true));
  ftpsclient.connect(HOST_ADDR, HOST_PORT); // Using port 990
  ftpsclient.enterLocalPassiveMode();
  ftpsclient.user(USERID);
  ftpsclient.pass(PASSWORD);
  ftpsclient.setFileType(FTP.BINARY_FILE_TYPE);
  ftpsclient.changeWorkingDirectory(REMOTE_DIR);
  ftpsclient.printWorkingDirectory();
  FTPFile[] ftpfiles = ftpsclient.listFiles(); // This is where it breaks
  </code></pre>
  
  <p>I've tried specifying the directory explicitly and using the default:</p>
  
  <pre><code>FTPFile[] ftpfiles = ftpsclient.listFiles();
  FTPFile[] ftpfiles = ftpsclient.listFiles(REMOTE_DIR);
  </code></pre>
  
  <p>... but both give the same result. This is the output of the debugging info:</p>
  
  <pre><code>220 FTPS (Version  Thu Dec 10 17:23:00 2015) server ready.
  USER ****
  331 Password required for ****.
  PASS ****
  230 User **** logged in.
  TYPE I
  200 Type set to I
  CWD outbound/directory
  250 CWD Command successful.
  PWD
  257 "/usr/path/to/outbound/directory" is current directory.
  SYST
  215 UNIX
  PASV
  227 Entering Passive Mode (XX,XX,XX,XX,24,140) ***Edit: port 6284
  LIST
  150 Opening data connection for '/bin/ls'.
  </code></pre>
  
  <p>Then it times out after 30 seconds with this stack trace:</p>
  
  <pre><code>Stack Trace: org.apache.commons.net.ftp.FTPConnectionClosedException: Connection closed without indication.
      at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:317)
      at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:294)
      at org.apache.commons.net.ftp.FTP.getReply(FTP.java:692)
      at org.apache.commons.net.ftp.FTPClient.completePendingCommand(FTPClient.java:1813)
      at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:3308)
      at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:3271)
      at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2930)
  </code></pre>
  
  <p>I've checked my firewall settings and that host is allowed to connect via port 990 and 6200-6300.</p>
  
  <p>I've also read <a href="https://stackoverflow.com/questions/15790074/ftpclient-listfiles-not-working">FTPClient.listFiles not working</a> and <a href="https://stackoverflow.com/questions/29570165/java-application-hanging-during-list-command-to-ftp-server-apache-commons-ftpcl">Java application hanging during LIST command to FTP Server (Apache Commons FTPClient)</a> and neither of these have helped with my problem.</p>
  
  <p>EDIT: It looks as though FTPClient is not recognizing the data channel. I tried uploading a file instead of doing a listing, and it died after the "150 Opening data connection" message. I've confirmed that the ports assigned to the data connection from the PASV command are NOT blocked by our firewall.</p>
  
  <p>Any ideas?</p>