I'm working on an Android project that requires FTP download to be paused/resumed.
Here is the code I use for FTP connection:
ftpClient.setConnectTimeout(25000);
ftpClient.login("login", "password");
ftpClient.changeWorkingDirectory("/audio");
ftpClient.enterLocalPassiveMode();
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
then I start download:
OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(localFile));
byte[] bytesArray = new byte[4096];
int bytesRead = -1;
totalRead = 0;
if (localFileSize > 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();
and I try to pause using abort
like this:
if (ftpClient.abort()) {
//connection aborted!;
}
But it seems that abort
doesn't work while there is an active download as mentioned here: https://issues.apache.org/jira/browse/NET-419
Is there any way I can perform pause/resume for FTP downloads in Android?