|
|
@ -27,6 +27,7 @@ import aria.apache.commons.net.ftp.FTPSClient; |
|
|
|
import com.arialyy.aria.core.AriaConfig; |
|
|
|
import com.arialyy.aria.core.AriaConfig; |
|
|
|
import com.arialyy.aria.core.FtpUrlEntity; |
|
|
|
import com.arialyy.aria.core.FtpUrlEntity; |
|
|
|
import com.arialyy.aria.core.common.AbsEntity; |
|
|
|
import com.arialyy.aria.core.common.AbsEntity; |
|
|
|
|
|
|
|
import com.arialyy.aria.core.common.CompleteInfo; |
|
|
|
import com.arialyy.aria.core.common.FtpConnectionMode; |
|
|
|
import com.arialyy.aria.core.common.FtpConnectionMode; |
|
|
|
import com.arialyy.aria.core.loader.IInfoTask; |
|
|
|
import com.arialyy.aria.core.loader.IInfoTask; |
|
|
|
import com.arialyy.aria.core.loader.ILoaderVisitor; |
|
|
|
import com.arialyy.aria.core.loader.ILoaderVisitor; |
|
|
@ -55,7 +56,8 @@ public abstract class AbsFtpInfoTask<ENTITY extends AbsEntity, TASK_WRAPPER exte |
|
|
|
private int mConnectTimeOut; |
|
|
|
private int mConnectTimeOut; |
|
|
|
protected long mSize = 0; |
|
|
|
protected long mSize = 0; |
|
|
|
protected String charSet = "UTF-8"; |
|
|
|
protected String charSet = "UTF-8"; |
|
|
|
protected Callback callback; |
|
|
|
private Callback callback; |
|
|
|
|
|
|
|
private boolean isStop = false, isCancel = false; |
|
|
|
|
|
|
|
|
|
|
|
public AbsFtpInfoTask(TASK_WRAPPER taskWrapper) { |
|
|
|
public AbsFtpInfoTask(TASK_WRAPPER taskWrapper) { |
|
|
|
mTaskWrapper = taskWrapper; |
|
|
|
mTaskWrapper = taskWrapper; |
|
|
@ -81,6 +83,14 @@ public abstract class AbsFtpInfoTask<ENTITY extends AbsEntity, TASK_WRAPPER exte |
|
|
|
protected abstract void handelFileInfo(FTPClient client, FTPFile[] files, |
|
|
|
protected abstract void handelFileInfo(FTPClient client, FTPFile[] files, |
|
|
|
String convertedRemotePath) throws IOException; |
|
|
|
String convertedRemotePath) throws IOException; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override public void stop() { |
|
|
|
|
|
|
|
isStop = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override public void cancel() { |
|
|
|
|
|
|
|
isCancel = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override public void setCallback(Callback callback) { |
|
|
|
@Override public void setCallback(Callback callback) { |
|
|
|
this.callback = callback; |
|
|
|
this.callback = callback; |
|
|
|
} |
|
|
|
} |
|
|
@ -101,10 +111,10 @@ public abstract class AbsFtpInfoTask<ENTITY extends AbsEntity, TASK_WRAPPER exte |
|
|
|
handelFileInfo(client, files, convertedRemotePath); |
|
|
|
handelFileInfo(client, files, convertedRemotePath); |
|
|
|
} catch (IOException e) { |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
e.printStackTrace(); |
|
|
|
failDownload(client, "FTP错误信息", e, true); |
|
|
|
handleFail(client, "FTP错误信息", e, true); |
|
|
|
} catch (InterruptedException e) { |
|
|
|
} catch (InterruptedException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
e.printStackTrace(); |
|
|
|
failDownload(client, "FTP错误信息", e, true); |
|
|
|
handleFail(client, "FTP错误信息", e, true); |
|
|
|
} finally { |
|
|
|
} finally { |
|
|
|
closeClient(client); |
|
|
|
closeClient(client); |
|
|
|
} |
|
|
|
} |
|
|
@ -146,7 +156,7 @@ public abstract class AbsFtpInfoTask<ENTITY extends AbsEntity, TASK_WRAPPER exte |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (client == null) { |
|
|
|
if (client == null) { |
|
|
|
failDownload(client, String.format("链接失败, url: %s", mTaskOption.getUrlEntity().url), null, |
|
|
|
handleFail(client, String.format("链接失败, url: %s", mTaskOption.getUrlEntity().url), null, |
|
|
|
true); |
|
|
|
true); |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
@ -168,14 +178,14 @@ public abstract class AbsFtpInfoTask<ENTITY extends AbsEntity, TASK_WRAPPER exte |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!loginSuccess) { |
|
|
|
if (!loginSuccess) { |
|
|
|
failDownload(client, "登录失败", null, false); |
|
|
|
handleFail(client, "登录失败", null, false); |
|
|
|
client.disconnect(); |
|
|
|
client.disconnect(); |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int reply = client.getReplyCode(); |
|
|
|
int reply = client.getReplyCode(); |
|
|
|
if (!FTPReply.isPositiveCompletion(reply)) { |
|
|
|
if (!FTPReply.isPositiveCompletion(reply)) { |
|
|
|
failDownload(client, String.format("无法连接到ftp服务器,filePath: %s, url: %s", mEntity.getKey(), |
|
|
|
handleFail(client, String.format("无法连接到ftp服务器,filePath: %s, url: %s", mEntity.getKey(), |
|
|
|
mTaskOption.getUrlEntity().url), null, true); |
|
|
|
mTaskOption.getUrlEntity().url), null, true); |
|
|
|
client.disconnect(); |
|
|
|
client.disconnect(); |
|
|
|
return null; |
|
|
|
return null; |
|
|
@ -299,7 +309,7 @@ public abstract class AbsFtpInfoTask<ENTITY extends AbsEntity, TASK_WRAPPER exte |
|
|
|
for (FTPFile file : files) { |
|
|
|
for (FTPFile file : files) { |
|
|
|
if (file.isFile()) { |
|
|
|
if (file.isFile()) { |
|
|
|
size += file.getSize(); |
|
|
|
size += file.getSize(); |
|
|
|
handleFile(path + file.getName(), file); |
|
|
|
handleFile(client, path + file.getName(), file); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
String remotePath = CommonUtil.convertFtpChar(charSet, path + file.getName()); |
|
|
|
String remotePath = CommonUtil.convertFtpChar(charSet, path + file.getName()); |
|
|
|
size += getFileSize(client.listFiles(remotePath), client, path + file.getName()); |
|
|
|
size += getFileSize(client.listFiles(remotePath), client, path + file.getName()); |
|
|
@ -314,10 +324,13 @@ public abstract class AbsFtpInfoTask<ENTITY extends AbsEntity, TASK_WRAPPER exte |
|
|
|
* @param remotePath ftp服务器文件夹路径 |
|
|
|
* @param remotePath ftp服务器文件夹路径 |
|
|
|
* @param ftpFile ftp服务器上对应的文件 |
|
|
|
* @param ftpFile ftp服务器上对应的文件 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected void handleFile(String remotePath, FTPFile ftpFile) { |
|
|
|
protected void handleFile(FTPClient client, String remotePath, FTPFile ftpFile) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected void failDownload(FTPClient client, String msg, Exception e, boolean needRetry) { |
|
|
|
protected void handleFail(FTPClient client, String msg, Exception e, boolean needRetry) { |
|
|
|
|
|
|
|
if (isStop || isCancel) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
if (callback != null) { |
|
|
|
if (callback != null) { |
|
|
|
if (client == null) { |
|
|
|
if (client == null) { |
|
|
|
msg = "创建ftp客户端失败"; |
|
|
|
msg = "创建ftp客户端失败"; |
|
|
@ -332,6 +345,10 @@ public abstract class AbsFtpInfoTask<ENTITY extends AbsEntity, TASK_WRAPPER exte |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void onSucceed(CompleteInfo info){ |
|
|
|
|
|
|
|
callback.onSucceed(mEntity.getKey(), info); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override public void accept(ILoaderVisitor visitor) { |
|
|
|
@Override public void accept(ILoaderVisitor visitor) { |
|
|
|
visitor.addComponent(this); |
|
|
|
visitor.addComponent(this); |
|
|
|
} |
|
|
|
} |
|
|
|