|
|
@ -32,11 +32,10 @@ import java.io.IOException; |
|
|
|
import java.io.UnsupportedEncodingException; |
|
|
|
import java.io.UnsupportedEncodingException; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Created by Aria.Lao on 2017/7/28. |
|
|
|
* Created by Aria.Lao on 2017/7/28. FTP 单线程上传任务,需要FTP 服务器给用户打开append和write的权限 |
|
|
|
* FTP 单线程上传任务,需要FTP 服务器给用户打开append和write的权限 |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
class FtpThreadTask extends AbsFtpThreadTask<UploadEntity, UploadTaskEntity> { |
|
|
|
class FtpThreadTask extends AbsFtpThreadTask<UploadEntity, UploadTaskEntity> { |
|
|
|
private final String TAG = "FtpUploadThreadTask"; |
|
|
|
private final String TAG = "FtpThreadTask"; |
|
|
|
private String dir, remotePath; |
|
|
|
private String dir, remotePath; |
|
|
|
|
|
|
|
|
|
|
|
FtpThreadTask(StateConstance constance, IEventListener listener, |
|
|
|
FtpThreadTask(StateConstance constance, IEventListener listener, |
|
|
@ -85,8 +84,8 @@ class FtpThreadTask extends AbsFtpThreadTask<UploadEntity, UploadTaskEntity> { |
|
|
|
//file.skipBytes((int) mConfig.START_LOCATION);
|
|
|
|
//file.skipBytes((int) mConfig.START_LOCATION);
|
|
|
|
file.seek(mConfig.START_LOCATION); |
|
|
|
file.seek(mConfig.START_LOCATION); |
|
|
|
} |
|
|
|
} |
|
|
|
upload(client, file); |
|
|
|
boolean complete = upload(client, file); |
|
|
|
if (isBreak()) { |
|
|
|
if (!complete || isBreak()) { |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
ALog.i(TAG, |
|
|
|
ALog.i(TAG, |
|
|
@ -131,7 +130,13 @@ class FtpThreadTask extends AbsFtpThreadTask<UploadEntity, UploadTaskEntity> { |
|
|
|
SERVER_CHARSET); |
|
|
|
SERVER_CHARSET); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void upload(final FTPClient client, final BufferedRandomAccessFile bis) |
|
|
|
/** |
|
|
|
|
|
|
|
* 上传 |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @return {@code true}上传成功、{@code false} 上传失败 |
|
|
|
|
|
|
|
* @throws IOException |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private boolean upload(final FTPClient client, final BufferedRandomAccessFile bis) |
|
|
|
throws IOException { |
|
|
|
throws IOException { |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
@ -156,12 +161,18 @@ class FtpThreadTask extends AbsFtpThreadTask<UploadEntity, UploadTaskEntity> { |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} catch (IOException e) { |
|
|
|
} catch (IOException e) { |
|
|
|
|
|
|
|
String msg = String.format("文件上传错误,错误码为:%s, msg:%s, filePath: %s", client.getReplyCode(), |
|
|
|
|
|
|
|
client.getReplyString(), mEntity.getFilePath()); |
|
|
|
|
|
|
|
if (client.isConnected()) { |
|
|
|
|
|
|
|
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(mChildCurrentLocation, |
|
|
|
fail(mChildCurrentLocation, |
|
|
|
new AriaIOException(TAG, String.format("上传失败,filePath: %s", mEntity.getFilePath()), e)); |
|
|
|
new AriaIOException(TAG, msg, e)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int reply = client.getReplyCode(); |
|
|
|
int reply = client.getReplyCode(); |
|
|
@ -175,6 +186,8 @@ class FtpThreadTask extends AbsFtpThreadTask<UploadEntity, UploadTaskEntity> { |
|
|
|
if (client.isConnected()) { |
|
|
|
if (client.isConnected()) { |
|
|
|
client.disconnect(); |
|
|
|
client.disconnect(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|