Answer the question
In order to leave comments, you need to log in
How to upload a list of files to an Ftp server?
This code stops working after transferring the first file. Help me figure out what's wrong.
@Override
protected Void doInBackground(Void... voids){
FTPClient client = new FTPClient();
FileInputStream fis = null;
OutputStream outputStream;
byte[] buffer = new byte[BUFFER_SIZE];
int totalBytesRead = 0;
try {
client.connect(host,port);
client.login(username, password);
client.setFileType(FTP.BINARY_FILE_TYPE);
for (File file : uploadFile){
fis = new FileInputStream(file);
outputStream = client.storeFileStream(file.getName());
int bytesRead;
while ((bytesRead = fis.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
totalBytesRead += bytesRead;
int percentCompleted = (totalBytesRead * 100 / length);
Log.d("PROGRESS", String.valueOf(totalBytesRead)+" "+String.valueOf(percentCompleted));
onProgressUpdate(totalBytesRead);
}
}
client.logout();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (fis != null) {
fis.close();
}
client.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question