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