title: FTPClient download file Access is denied
body: <p>I am trying to download a file from an FTP server using Apache commons 2.0.</p>
  
  <p>The following code is giving this error: "Access is denied".</p>
  
  <p>Getting files list properly but whenever the download section executes the mentioned error occurs. </p>
  
  <pre><code>public class FTP extends Thread{
      @Override
  
      public void run() {
          try {
              FTPClient client=new FTPClient();
              client.connect(InetAddress.getByName("192.168.0.100"),2221);
              System.out.println(client.getReplyCode());
              boolean status=client.login("francis", "francis");
              client.enterLocalPassiveMode();
              System.out.println(status);                
              FTPFile[] files=client.listFiles();
              System.out.println("Printing files list :");    
              for(int i=0; i&lt;files.length; i++){
                  System.out.println(files[i].getName());
                  client.setFileTransferMode(BINARY_FILE_TYPE);
                  client.setFileType(BINARY_FILE_TYPE);
                  byte[] buffer=new byte[1024];                   
                  if(files[i].isFile()){
                      System.out.println("Downloading........");
                      InputStream 
                      ins=client.retrieveFileStream(files[i].getName());
                      OutputStream outstream=new 
                      FileOutputStream("c:/"+files[i].getName());
                      int n=0;
  
                      while(ins.read(buffer)!=-1){
                          n=ins.read(buffer);
                          outstream.write(buffer,0,n);
                      }                       
                      File downloaded=new File("c:/"+files[i].getName());
  
                      if(files[i].getSize()==downloaded.length()){
                          System.out.println("Download succesfull..");
                      } else {
                          System.out.println("Error downloading file");
                      }
                  }
              }
          } catch (IOException ex) {
              Logger.getLogger(FTP.class.getName()).log(Level.SEVERE, null, ex);
          }
      }
  
      public static void main(String[] args) throws UnknownHostException, IOException {
          FTP thread=new FTP();
          thread.start();
      }
  }
  </code></pre>
  
  <p>getting the following error on console </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>   
  Printing files list :&lt;br&gt;
  DCIM&lt;br&gt;
  Download&lt;br&gt;
  LGBackup&lt;br&gt;
  Movies&lt;br&gt;
  Music&lt;br&gt;
  Pictures&lt;br&gt;
  Podcasts&lt;br&gt;
  SHAREit&lt;br&gt;
  Snapchat&lt;br&gt;&lt;br&gt;
  WhatsApp&lt;br&gt;
  MobileTmoney.txt&lt;br&gt;
  Downloading........&lt;br&gt;
  Mar 27, 2018 12:41:17 PM ftp.FTP run&lt;br&gt;
  SEVERE: null&lt;br&gt;
  java.io.FileNotFoundException: c:\MobileTmoney.txt (Access is denied)&lt;br&gt;
   at java.io.FileOutputStream.op&lt;br&gt;en0(Native Method)&lt;br&gt;
   at ftp.FTP.run(FTP.java:49)&lt;br&gt;</code></pre>
  </div>
  </div>
  </p>