|
|
|
@ -35,7 +35,7 @@ import org.apache.commons.net.ftp.OnFtpInputStreamListener; |
|
|
|
|
* FTP 单线程上传任务,需要FTP 服务器给用户打开删除和读入IO的权限 |
|
|
|
|
*/ |
|
|
|
|
class FtpThreadTask extends AbsFtpThreadTask<UploadEntity, UploadTaskEntity> { |
|
|
|
|
private final String TAG = "FtpThreadTask"; |
|
|
|
|
private final String TAG = "FtpUploadThreadTask"; |
|
|
|
|
private String dir, remotePath; |
|
|
|
|
|
|
|
|
|
FtpThreadTask(StateConstance constance, IEventListener listener, |
|
|
|
@ -61,25 +61,13 @@ class FtpThreadTask extends AbsFtpThreadTask<UploadEntity, UploadTaskEntity> { |
|
|
|
|
client = createClient(); |
|
|
|
|
if (client == null) return; |
|
|
|
|
initPath(); |
|
|
|
|
if (client.makeDirectory(dir)) { |
|
|
|
|
fail(mChildCurrentLocation, "创建文件夹失败", null); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (client.changeWorkingDirectory(dir)) { |
|
|
|
|
fail(mChildCurrentLocation, "选择工作文件夹失败", null); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
client.makeDirectory(dir); |
|
|
|
|
client.changeWorkingDirectory(dir); |
|
|
|
|
client.setRestartOffset(mConfig.START_LOCATION); |
|
|
|
|
int reply = client.getReplyCode(); |
|
|
|
|
if (reply == FTPReply.SYNTAX_ERROR_IN_ARGUMENTS) { |
|
|
|
|
if (!FTPReply.isPositivePreliminary(reply) && reply != FTPReply.FILE_ACTION_OK) { |
|
|
|
|
fail(mChildCurrentLocation, "上传失败,错误码为:" + reply + ",msg:" + client.getReplyString(), null); |
|
|
|
|
client.disconnect(); |
|
|
|
|
fail(mChildCurrentLocation, |
|
|
|
|
"上传失败,FTP没有打开写权限,错误码为:" + reply + ",msg:" + client.getReplyString(), null); |
|
|
|
|
return; |
|
|
|
|
} else if (!FTPReply.isPositivePreliminary(reply) && reply != FTPReply.COMMAND_OK) { |
|
|
|
|
client.disconnect(); |
|
|
|
|
fail(mChildCurrentLocation, |
|
|
|
|
"上传失败,FTP没有打开写权限,错误码为:" + reply + ",msg:" + client.getReplyString(), null); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -126,7 +114,7 @@ class FtpThreadTask extends AbsFtpThreadTask<UploadEntity, UploadTaskEntity> { |
|
|
|
|
private void initPath() throws UnsupportedEncodingException { |
|
|
|
|
dir = new String(mTaskEntity.urlEntity.remotePath.getBytes(charSet), SERVER_CHARSET); |
|
|
|
|
remotePath = new String( |
|
|
|
|
(mTaskEntity.urlEntity.remotePath + "/" + mEntity.getFileName()).getBytes(charSet), |
|
|
|
|
("/" + mTaskEntity.urlEntity.remotePath + mEntity.getFileName()).getBytes(charSet), |
|
|
|
|
SERVER_CHARSET); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -134,6 +122,7 @@ class FtpThreadTask extends AbsFtpThreadTask<UploadEntity, UploadTaskEntity> { |
|
|
|
|
throws IOException { |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
ALog.d(TAG, "remotePath【" + remotePath + "】"); |
|
|
|
|
client.storeFile(remotePath, new FtpFISAdapter(bis), new OnFtpInputStreamListener() { |
|
|
|
|
boolean isStoped = false; |
|
|
|
|
|
|
|
|
@ -160,11 +149,13 @@ class FtpThreadTask extends AbsFtpThreadTask<UploadEntity, UploadTaskEntity> { |
|
|
|
|
|
|
|
|
|
int reply = client.getReplyCode(); |
|
|
|
|
if (!FTPReply.isPositiveCompletion(reply)) { |
|
|
|
|
if (reply != FTPReply.TRANSFER_ABORTED) { |
|
|
|
|
fail(mChildCurrentLocation, "上传文件错误,错误码为:" + reply + ",msg:" + client.getReplyString(), |
|
|
|
|
null); |
|
|
|
|
} |
|
|
|
|
if (client.isConnected()) { |
|
|
|
|
client.disconnect(); |
|
|
|
|
} |
|
|
|
|
if (reply == FTPReply.TRANSFER_ABORTED) return; |
|
|
|
|
fail(mChildCurrentLocation, "上传文件错误,错误码为:" + reply, null); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|