title: ftp doesn't download the file properly in java?
body: <p>When i download file with following code it just write the file to destination on local but file size are all zero. <strong>Can anybody say Why this happen and how to fix it?</strong></p>
  
  <pre><code>import org.apache.commons.net.ftp.FTPClient;
  import org.apache.commons.net.ftp.FTPFile;
  import java.io.FileOutputStream;
  import java.io.IOException;
  
  public class FtpDownload {
  public static void main(String[] args) {
      FTPClient client = new FTPClient();
      FileOutputStream fos = null;
      String filename = "config.zip";
      try {
          client.connect("ftpsrv");
          client.login("user", "user");
  
          for (FTPFile file : client.listFiles()) {
              filename = "C:\\tmp\\user\\" + file.getName();
              if (file.isFile()) {
                  fos = new FileOutputStream(filename);
                  client.retrieveFile(filename, fos);
                  System.out.println(file.getName());
              } else if (file.isDirectory()) {
                  System.out.println("directory: " + file.getName());
              }
          }
  
      } catch (IOException e) {
          e.printStackTrace();
      } finally {
          try {
              if (fos != null) {
                  fos.close();
              }
              client.disconnect();
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  
  }
  }
  </code></pre>