title: Android FTP download pause/resume
body: <p>I'm working on an Android project that requires FTP download to be paused/resumed.</p>
  
  <p>Here is the code I use for FTP connection:</p>
  
  <pre><code>ftpClient.setConnectTimeout(25000);
  ftpClient.login("login", "password");
  ftpClient.changeWorkingDirectory("/audio");
  ftpClient.enterLocalPassiveMode();
  ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
  </code></pre>
  
  <p>then I start download:</p>
  
  <pre><code>OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(localFile));
  
  byte[] bytesArray = new byte[4096];
  int bytesRead = -1;
  totalRead = 0;
  
  if (localFileSize &gt; 0) {
      ftpClient.setRestartOffset(localFileSize);
      ftpClient.restart(localFileSize);
  }
  
  InputStream inputStream = ftpClient.retrieveFileStream(fileName);
  
  while ((bytesRead = inputStream.read(bytesArray)) != -1) {
      totalRead += bytesRead;
      outputStream.write(bytesArray, (int) localFileSize, bytesRead);
  }
  
  success = ftpClient.completePendingCommand();
  </code></pre>
  
  <p>and I try to pause using <code>abort</code> like this:                            </p>
  
  <pre><code>if (ftpClient.abort()) {
     //connection aborted!;
  }
  </code></pre>
  
  <p>But it seems that <code>abort</code> doesn't work while there is an active download as mentioned here: <a href="https://issues.apache.org/jira/browse/NET-419" rel="nofollow">https://issues.apache.org/jira/browse/NET-419</a></p>
  
  <p><strong>Is there any way I can perform pause/resume for FTP downloads in Android?</strong></p>