title: URLConnection FTP list files
body: <pre><code>URL url =  new URL(&quot;ftp://user:pass@ftp.example.com/thefolder/&quot;);
  URLConnection connection = url.openConnection();
  ...
  // List files in folder...
  </code></pre>
  <p>Using something like the above, I was wondering how I could grab a list of files within folder 'thefolder'?</p>
  <hr />
  <p>Following on from this original question, I have put together this simple FTP connection which is all working and looking good. It can see all files in the /live/conf/ location and copies them all to the local /conf/ location.</p>
  <p>The only issue is, it is copying the files but there's no content.They are all 0KB and empty.</p>
  <p>Can anyone see anything obvious that'd be copying the filename but not file content?</p>
  <pre><code>try {
      FTPClient ftp = new FTPClient();
      ftp.connect(&quot;000.000.000.000&quot;);
      ftp.login(&quot;USER&quot;, &quot;PASSWORD&quot;);
      ftp.enterLocalPassiveMode();
      ftp.setFileType(FTP.BINARY_FILE_TYPE);
  
      FTPFile[] files = ftp.listFiles(&quot;/live/conf/&quot;);
      for (int i=0; i &lt; files.length; i++) {
          if (files[i].getName().contains(&quot;.csv&quot;)) {
  
              String remoteFile1 = files[i].getName();
              File downloadFile1 = new File(&quot;/var/local/import/conf/&quot;+files[i].getName());
              OutputStream outputStream1 = new BufferedOutputStream(new FileOutputStream(downloadFile1));
              ftp.retrieveFile(remoteFile1, outputStream1);
              outputStream1.close();                  
  
          }
      }
      ftp.disconnect();
  } catch (SocketException ex) {
      ex.printStackTrace();
  } catch (IOException ex) {
      ex.printStackTrace();
  }   
  </code></pre>