@Robert Paasche
The code is used in an AsyncTask and there's more error handling to it
(including proper error messages,...), I just simplified it. ;)
Have you ever tested it with images too? Text files always seem to download
properly (no matter what size), it's just the images that are messed up.
Thanks for the code snippet, I just ran my app with it multiple times and the
files are all the right size, even the images, but no program is able to
actually open them, so not sure what's going on with that now:
if(singleFile.length > 0) { //check if file exists
String localPath = localFolder + File.separator + filename;
FTPFile single = singleFile[0];
InputStream inStream = ftpClient.retrieveFileStream(filename);
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int nRead;
byte[] data = new byte[(int) (single.getSize())]; //length was "*2" but why?
while ((nRead = inStream.read(data, 0, data.length)) != -1) {
buffer.write(data, 0, nRead);
}
buffer.flush();
inStream.close();
FileOutputStream fos = new FileOutputStream(localPath);
fos.write(data);
fos.flush();
fos.close();
if(ftpClient.completePendingCommand()) {
Log.d(TAG,"DONE");
} else {
Log.d(TAG,"NOT DONE");
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]