|
|
@ -34,6 +34,7 @@ import java.io.UnsupportedEncodingException; |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
class FtpUThreadTaskAdapter extends BaseFtpThreadTaskAdapter { |
|
|
|
class FtpUThreadTaskAdapter extends BaseFtpThreadTaskAdapter { |
|
|
|
private String dir, remotePath; |
|
|
|
private String dir, remotePath; |
|
|
|
|
|
|
|
private boolean storeFail = false; |
|
|
|
|
|
|
|
|
|
|
|
FtpUThreadTaskAdapter(SubThreadConfig config) { |
|
|
|
FtpUThreadTaskAdapter(SubThreadConfig config) { |
|
|
|
super(config); |
|
|
|
super(config); |
|
|
@ -67,8 +68,7 @@ class FtpUThreadTaskAdapter extends BaseFtpThreadTaskAdapter { |
|
|
|
file = |
|
|
|
file = |
|
|
|
new BufferedRandomAccessFile(getThreadConfig().tempFile, "rwd", |
|
|
|
new BufferedRandomAccessFile(getThreadConfig().tempFile, "rwd", |
|
|
|
getTaskConfig().getBuffSize()); |
|
|
|
getTaskConfig().getBuffSize()); |
|
|
|
if (getThreadRecord().startLocation != 0) { |
|
|
|
if (getThreadRecord().startLocation > 0) { |
|
|
|
//file.skipBytes((int) getThreadConfig().START_LOCATION);
|
|
|
|
|
|
|
|
file.seek(getThreadRecord().startLocation); |
|
|
|
file.seek(getThreadRecord().startLocation); |
|
|
|
} |
|
|
|
} |
|
|
|
boolean complete = upload(client, file); |
|
|
|
boolean complete = upload(client, file); |
|
|
@ -79,6 +79,7 @@ class FtpUThreadTaskAdapter extends BaseFtpThreadTaskAdapter { |
|
|
|
String.format("任务【%s】线程__%s__上传完毕", getEntity().getKey(), getThreadRecord().threadId)); |
|
|
|
String.format("任务【%s】线程__%s__上传完毕", getEntity().getKey(), getThreadRecord().threadId)); |
|
|
|
complete(); |
|
|
|
complete(); |
|
|
|
} catch (IOException e) { |
|
|
|
} catch (IOException e) { |
|
|
|
|
|
|
|
e.printStackTrace(); |
|
|
|
fail(new AriaIOException(TAG, |
|
|
|
fail(new AriaIOException(TAG, |
|
|
|
String.format("上传失败,filePath: %s, uploadUrl: %s", getEntity().getFilePath(), |
|
|
|
String.format("上传失败,filePath: %s, uploadUrl: %s", getEntity().getFilePath(), |
|
|
|
getThreadConfig().url)), true); |
|
|
|
getThreadConfig().url)), true); |
|
|
@ -118,10 +119,11 @@ class FtpUThreadTaskAdapter extends BaseFtpThreadTaskAdapter { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private boolean upload(final FTPClient client, final BufferedRandomAccessFile bis) |
|
|
|
private boolean upload(final FTPClient client, final BufferedRandomAccessFile bis) |
|
|
|
throws IOException { |
|
|
|
throws IOException { |
|
|
|
|
|
|
|
final FtpFISAdapter fa = new FtpFISAdapter(bis); |
|
|
|
|
|
|
|
storeFail = false; |
|
|
|
try { |
|
|
|
try { |
|
|
|
ALog.d(TAG, String.format("remotePath: %s", remotePath)); |
|
|
|
ALog.d(TAG, String.format("remotePath: %s", remotePath)); |
|
|
|
client.storeFile(remotePath, new FtpFISAdapter(bis), new OnFtpInputStreamListener() { |
|
|
|
client.storeFile(remotePath, fa, new OnFtpInputStreamListener() { |
|
|
|
boolean isStoped = false; |
|
|
|
boolean isStoped = false; |
|
|
|
|
|
|
|
|
|
|
|
@Override public void onFtpInputStream(FTPClient client, long totalBytesTransferred, |
|
|
|
@Override public void onFtpInputStream(FTPClient client, long totalBytesTransferred, |
|
|
@ -137,23 +139,30 @@ class FtpUThreadTaskAdapter extends BaseFtpThreadTaskAdapter { |
|
|
|
progress(bytesTransferred); |
|
|
|
progress(bytesTransferred); |
|
|
|
} catch (IOException e) { |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
storeFail = true; |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
fa.close(); |
|
|
|
|
|
|
|
} catch (IOException e1) { |
|
|
|
|
|
|
|
e1.printStackTrace(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
closeClient(client); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} catch (IOException e) { |
|
|
|
} catch (IOException e) { |
|
|
|
String msg = String.format("文件上传错误,错误码为:%s, msg:%s, filePath: %s", client.getReplyCode(), |
|
|
|
String msg = String.format("文件上传错误,错误码为:%s, msg:%s, filePath: %s", client.getReplyCode(), |
|
|
|
client.getReplyString(), getEntity().getFilePath()); |
|
|
|
client.getReplyString(), getEntity().getFilePath()); |
|
|
|
if (client.isConnected()) { |
|
|
|
closeClient(client); |
|
|
|
client.disconnect(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (e.getMessage().contains("AriaIOException caught while copying")) { |
|
|
|
if (e.getMessage().contains("AriaIOException caught while copying")) { |
|
|
|
e.printStackTrace(); |
|
|
|
e.printStackTrace(); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
fail(new AriaIOException(TAG, msg, e), true); |
|
|
|
fail(new AriaIOException(TAG, msg, e), !storeFail); |
|
|
|
} |
|
|
|
} |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (storeFail) { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
int reply = client.getReplyCode(); |
|
|
|
int reply = client.getReplyCode(); |
|
|
|
if (!FTPReply.isPositiveCompletion(reply)) { |
|
|
|
if (!FTPReply.isPositiveCompletion(reply)) { |
|
|
|
if (reply != FTPReply.TRANSFER_ABORTED) { |
|
|
|
if (reply != FTPReply.TRANSFER_ABORTED) { |
|
|
@ -161,9 +170,7 @@ class FtpUThreadTaskAdapter extends BaseFtpThreadTaskAdapter { |
|
|
|
String.format("文件上传错误,错误码为:%s, msg:%s, filePath: %s", reply, client.getReplyString(), |
|
|
|
String.format("文件上传错误,错误码为:%s, msg:%s, filePath: %s", reply, client.getReplyString(), |
|
|
|
getEntity().getFilePath())), false); |
|
|
|
getEntity().getFilePath())), false); |
|
|
|
} |
|
|
|
} |
|
|
|
if (client.isConnected()) { |
|
|
|
closeClient(client); |
|
|
|
client.disconnect(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
return true; |
|
|
|
return true; |
|
|
|