title: Android ftp download doesn't downloads file properly
body: <p>I'm new on android  programming. And I need to download videos, jpgs and pdfs from an ftp server to my android device.</p>
  
  <p>Here is my download code in a Thread</p>
  
  <pre><code>      MyFTPClient ftpclient=null;
        ftpclient = new MyFTPClient();
        status = ftpclient.ftpConnect("xxx.xxx.xxx.xxx", "username", "password", 21);
        if (status == true) {
        Log.d(TAG, "Connection Success");
            FTPFile[] filelist= ftpclient.ftpPrintFilesList("/httpdocs/");
            for(int i=0;i&lt;filelist.length;i++){
                if(filelist[i].getType()==1)
                {
                     File myFile = new File("/storage/sdcard0/App/"+filelist[i].getName());
                     if(!myFile.exists()){
                        File folder=new File("/storage/sdcard0/App/"+filelist[i].getName());
                        folder.mkdir();
                     }
                 }
                 else if(filelist[i].getType()==0)
                 {
                      ftpclient.ftpDownload("/httpdocs/"+filelist[i].getName(), "/storage/sdcard0/App/"+filelist[i].getName());
                 }
            }
            else {
                  Log.d(TAG, "Connection failed");
            }
  </code></pre>
  
  <p>This is my FTP client class</p>
  
  <pre><code>public boolean ftpConnect(String host, String username,
                            String password, int port)
  {
      try {
          mFTPClient = new FTPClient();
          mFTPClient.connect(host, port);
          mFTPClient.setFileType(FTP.BINARY_FILE_TYPE);
          if (FTPReply.isPositiveCompletion(mFTPClient.getReplyCode())) {
              boolean status = mFTPClient.login(username, password);
  
              mFTPClient.setFileType(FTP.ASCII_FILE_TYPE);
              mFTPClient.enterLocalPassiveMode();
  
              return status;
          }
      } catch(Exception e) {
          Log.d(TAG, "Error: could not connect to host " + host+"Cause: "+e.getCause() );
      }
      return false;
  } 
  
  
  public FTPFile[] ftpPrintFilesList(String dir_path)
  {
      try {
          FTPFile[] ftpFiles = mFTPClient.listFiles(dir_path);
          int length = ftpFiles.length;
  
          for (int i = 0; i &lt; length; i++) {
              String name = ftpFiles[i].getName();
              boolean isFile = ftpFiles[i].isFile();
  
              if (isFile) {
                  Log.i(TAG, "File : " + name);
              }
              else {
                  Log.i(TAG, "Directory : " + name);
              }
          }
  
          return ftpFiles;
      } catch(Exception e) {
          e.printStackTrace();
  
          return null;
      }
  } 
  
  public boolean ftpDownload(String srcFilePath, String desFilePath)
  {
      boolean status = false;
      try {
          FileOutputStream desFileStream = new FileOutputStream(desFilePath);;
          status = mFTPClient.retrieveFile(srcFilePath, desFileStream);
          desFileStream.flush();
          desFileStream.close();
  
          return status;
      } catch (Exception e) {
          Log.d(TAG, "download failed");
      }
  
      return status;
  } 
  </code></pre>
  
  <p>These codes dowloads files but when I want to open some pdfs or videos I get error "An error occured while opening the document"</p>
  
  <p>How can I handle the dowload code works properly? What can be the reasen of the error?</p>
  
  <p>P.S: The video files are 100-200 MB, pdf files are 1-5 MB</p>