diff --git a/Aria/build.gradle b/Aria/build.gradle index f95e9d8f..f45db0b2 100644 --- a/Aria/build.gradle +++ b/Aria/build.gradle @@ -22,8 +22,8 @@ dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.1.1' - compile project(':AriaAnnotations') -// compile 'com.arialyy.aria:aria-ftp-plug:1.0.3' +// compile project(':AriaAnnotations') + compile 'com.arialyy.aria:aria-ftp-plug:1.0.3' compile project(':AriaFtpPlug') } diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/AbsFtpInfoThread.java b/Aria/src/main/java/com/arialyy/aria/core/common/AbsFtpInfoThread.java index c118475e..7275ebd8 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/AbsFtpInfoThread.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/AbsFtpInfoThread.java @@ -79,7 +79,7 @@ public abstract class AbsFtpInfoThread */ @Deprecated public DownloadTarget load(@NonNull String url, boolean refreshInfo) { - CheckUtil.checkUrl(url); + url = CheckUtil.checkUrl(url); return new DownloadTarget(url, targetName, refreshInfo); } @@ -165,7 +165,7 @@ public class DownloadReceiver extends AbsReceiver { * @param refreshInfo 是否刷新下载信息 */ public FtpDownloadTarget loadFtp(@NonNull String url, boolean refreshInfo) { - CheckUtil.checkUrl(url); + url = CheckUtil.checkUrl(url); return new FtpDownloadTarget(url, targetName, refreshInfo); } @@ -183,7 +183,7 @@ public class DownloadReceiver extends AbsReceiver { * 加载ftp文件夹下载地址 */ public FtpDirDownloadTarget loadFtpDir(@NonNull String dirUrl) { - CheckUtil.checkUrl(dirUrl); + dirUrl = CheckUtil.checkUrl(dirUrl); return new FtpDirDownloadTarget(dirUrl, targetName); } @@ -239,7 +239,7 @@ public class DownloadReceiver extends AbsReceiver { * 通过下载链接获取下载实体 */ public DownloadEntity getDownloadEntity(String downloadUrl) { - CheckUtil.checkUrl(downloadUrl); + downloadUrl = CheckUtil.checkUrl(downloadUrl); return DbEntity.findFirst(DownloadEntity.class, "url=? and isGroupChild='false'", downloadUrl); } @@ -247,7 +247,7 @@ public class DownloadReceiver extends AbsReceiver { * 通过下载链接获取保存在数据库的下载任务实体 */ public DownloadTaskEntity getDownloadTask(String downloadUrl) { - CheckUtil.checkUrl(downloadUrl); + downloadUrl = CheckUtil.checkUrl(downloadUrl); DownloadEntity entity = getDownloadEntity(downloadUrl); if (entity == null || TextUtils.isEmpty(entity.getDownloadPath())) return null; return DbEntity.findFirst(DownloadTaskEntity.class, "key=? and isGroupTask='false'", diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpThreadTask.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpThreadTask.java index 4539e82e..48fb66f8 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpThreadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpThreadTask.java @@ -34,7 +34,7 @@ import org.apache.commons.net.ftp.FTPReply; * Ftp下载任务 */ class FtpThreadTask extends AbsFtpThreadTask { - private final String TAG = "FtpThreadTask"; + private final String TAG = "FtpDownloadThreadTask"; FtpThreadTask(StateConstance constance, IDownloadListener listener, SubThreadConfig downloadInfo) { @@ -64,22 +64,21 @@ class FtpThreadTask extends AbsFtpThreadTask } //发送第二次指令时,还需要再做一次判断 int reply = client.getReplyCode(); - if (reply == FTPReply.SYNTAX_ERROR_IN_ARGUMENTS) { - ALog.e(TAG, "FTP没有打开写权限,断点续传失败,将从0开始读文件"); - } else if (!FTPReply.isPositivePreliminary(reply) && reply != FTPReply.COMMAND_OK) { - client.disconnect(); + if (!FTPReply.isPositivePreliminary(reply) && reply != FTPReply.COMMAND_OK) { fail(mChildCurrentLocation, "获取文件信息错误,错误码为:" + reply + ",msg:" + client.getReplyString(), null); + client.disconnect(); return; } String remotePath = new String(mTaskEntity.urlEntity.remotePath.getBytes(charSet), SERVER_CHARSET); + ALog.i(TAG, "remotePath【" + remotePath + "】"); is = client.retrieveFileStream(remotePath); reply = client.getReplyCode(); if (!FTPReply.isPositivePreliminary(reply)) { - client.disconnect(); fail(mChildCurrentLocation, "获取流失败,错误码为:" + reply + ",msg:" + client.getReplyString(), null); + client.disconnect(); return; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java index 64aa80ca..c2cdafd0 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java @@ -16,12 +16,12 @@ package com.arialyy.aria.core.download.downloader; import android.text.TextUtils; -import android.util.Log; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.common.OnFileInfoCallback; import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.util.ALog; +import com.arialyy.aria.util.CheckUtil; import com.arialyy.aria.util.CommonUtil; import java.io.IOException; import java.net.HttpURLConnection; @@ -130,12 +130,14 @@ class HttpFileInfoThread implements Runnable { private void handle302Turn(HttpURLConnection conn) throws IOException { String newUrl = conn.getHeaderField(mTaskEntity.redirectUrlKey); ALog.d(TAG, "30x跳转,location【 " + mTaskEntity.redirectUrlKey + "】" + "新url为【" + newUrl + "】"); - if (TextUtils.isEmpty(newUrl) || newUrl.equalsIgnoreCase("null")) { + if (TextUtils.isEmpty(newUrl) || newUrl.equalsIgnoreCase("null") || !newUrl.startsWith( + "http")) { if (onFileInfoListener != null) { onFileInfoListener.onFail(mEntity.getUrl(), "获取重定向链接失败", false); } return; } + newUrl = CheckUtil.checkUrl(newUrl); String cookies = conn.getHeaderField("Set-Cookie"); conn = (HttpURLConnection) new URL(newUrl).openConnection(); conn = ConnectionHelp.setConnectParam(mTaskEntity, conn); diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsUploadTarget.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsUploadTarget.java index bfa627e9..be6541f1 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsUploadTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsUploadTarget.java @@ -35,7 +35,7 @@ public abstract class AbsUploadTarget { - 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 { 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 { 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 { 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 { 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); } } diff --git a/Aria/src/main/java/com/arialyy/aria/util/CheckUtil.java b/Aria/src/main/java/com/arialyy/aria/util/CheckUtil.java index 93eed2b9..103a5153 100644 --- a/Aria/src/main/java/com/arialyy/aria/util/CheckUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/util/CheckUtil.java @@ -74,7 +74,7 @@ public class CheckUtil { * 检查下载实体 */ public static void checkDownloadEntity(DownloadEntity entity) { - checkUrl(entity.getUrl()); + entity.setUrl(checkUrl(entity.getUrl())); checkPath(entity.getDownloadPath()); } @@ -88,14 +88,25 @@ public class CheckUtil { } /** - * 检测下载链接是否为null + * 检测下载链接是否合法,如果地址中path是"//"而不是"/"将会改为"/"; */ - public static void checkUrl(String url) { + public static String checkUrl(String url) { if (TextUtils.isEmpty(url)) { - throw new IllegalArgumentException("下载链接不能为null"); + throw new IllegalArgumentException("url不能为null"); } else if (!url.startsWith("http") && !url.startsWith("ftp")) { throw new IllegalArgumentException("url错误"); } + int index = url.indexOf("://"); + if (index == -1) { + throw new IllegalArgumentException("url不合法"); + } + String temp = url.substring(index + 3, url.length()); + if (temp.contains("//")) { + temp = url.substring(0, index + 3) + temp.replaceAll("//", "/"); + ALog.w(TAG, "url中含有//,//将转换为/,转换后的url为:" + temp); + return temp; + } + return url; } /** diff --git a/DEV_LOG.md b/DEV_LOG.md index 1c40411b..26aed643 100644 --- a/DEV_LOG.md +++ b/DEV_LOG.md @@ -1,4 +1,7 @@ ## 开发日志 + + v_3.3.14 + - 修复ftp上传和下载的兼容性问题 + - 如果url中的path有"//"将替换为"/" + v_3.3.13 - 添加`@Download.onWait、@Upload.onWait、@DownloadGroup.onWait`三个新注解,队列已经满了,继续创建新任务,任务处于等待中,将会执行被这三个注解标志的方法 - app被kill,但是还存在等待中的任务A;第二次重新启动,先创建一个新的任务B,Aria会自动把B放进等待队列中,这时再次创建任务A,会导致重复下载,进度错乱的问题;本版本已修复这个问题 diff --git a/README.md b/README.md index 5227aad2..743a102d 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ annotationProcessor 'com.arialyy.aria:aria-compiler:3.3.13' ``` 如果出现android support,请将 `compile 'com.arialyy.aria:aria-core:3.3.13'`替换为 ``` -compile('com.arialyy.aria:'){ +compile('com.arialyy.aria:aria-core:'){ exclude group: 'com.android.support' } ``` diff --git a/app/src/main/java/com/arialyy/simple/download/FtpDownloadActivity.java b/app/src/main/java/com/arialyy/simple/download/FtpDownloadActivity.java index 500995ae..6cf598ba 100644 --- a/app/src/main/java/com/arialyy/simple/download/FtpDownloadActivity.java +++ b/app/src/main/java/com/arialyy/simple/download/FtpDownloadActivity.java @@ -39,8 +39,10 @@ public class FtpDownloadActivity extends BaseActivity { @Override protected void onDestroy() { super.onDestroy(); - Aria.download(this).unRegister(); + //Aria.download(this).unRegister(); } } \ No newline at end of file diff --git a/app/src/main/java/com/arialyy/simple/upload/FtpUploadActivity.java b/app/src/main/java/com/arialyy/simple/upload/FtpUploadActivity.java index 8b34f75a..0cb66b11 100644 --- a/app/src/main/java/com/arialyy/simple/upload/FtpUploadActivity.java +++ b/app/src/main/java/com/arialyy/simple/upload/FtpUploadActivity.java @@ -34,8 +34,8 @@ import com.arialyy.simple.databinding.ActivityFtpUploadBinding; * Ftp 文件上传demo */ public class FtpUploadActivity extends BaseActivity { - private final String FILE_PATH = "/mnt/sdcard/gg.zip"; - private final String URL = "ftp://192.168.1.2:21/upload/测试"; + private final String FILE_PATH = "/mnt/sdcard/AriaPrj.zip"; + private final String URL = "ftp://192.168.1.6:21/aa/你好"; @Override protected void init(Bundle savedInstanceState) { setTile("D_FTP 文件上传"); @@ -56,7 +56,7 @@ public class FtpUploadActivity extends BaseActivity { public void onClick(View view) { switch (view.getId()) { case R.id.start: - Aria.upload(this).loadFtp(FILE_PATH).setUploadUrl(URL).login("lao", "123456").add(); + Aria.upload(this).loadFtp(FILE_PATH).setUploadUrl(URL).login("lao", "123456").start(); break; case R.id.stop: Aria.upload(this).loadFtp(FILE_PATH).stop();