ftp
This commit is contained in:
@ -23,5 +23,6 @@ dependencies {
|
||||
testCompile 'junit:junit:4.12'
|
||||
compile 'com.android.support:appcompat-v7:23.1.1'
|
||||
compile project(':AriaAnnotations')
|
||||
compile project(':AriaFtpPlug')
|
||||
}
|
||||
apply from: 'bintray-release.gradle'
|
||||
|
@ -58,13 +58,24 @@ public class DownloadReceiver extends AbsReceiver {
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载下载地址
|
||||
* 加载Http下载功能
|
||||
*/
|
||||
public DownloadTarget load(@NonNull String downloadUrl) {
|
||||
CheckUtil.checkDownloadUrl(downloadUrl);
|
||||
return new DownloadTarget(downloadUrl, targetName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载Ftp下载功能
|
||||
*
|
||||
* @param serverIp ftp服务器地址
|
||||
* @param port ftp端口
|
||||
* @param filePath 需要从ftp服务器上下载的文件的路径
|
||||
*/
|
||||
public FtpDownloadTarget load(String serverIp, String port, String filePath) {
|
||||
return new FtpDownloadTarget(serverIp, port, filePath, targetName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载下载地址,如果任务组的中的下载地址改变了,则任务从新的一个任务组
|
||||
*/
|
||||
|
@ -19,8 +19,11 @@ package com.arialyy.aria.core.download;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.download.downloader.FtpDownloadUtil;
|
||||
import com.arialyy.aria.core.download.downloader.IDownloadUtil;
|
||||
import com.arialyy.aria.core.download.downloader.SimpleDownloadUtil;
|
||||
import com.arialyy.aria.core.inf.AbsNormalTask;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.inf.IEntity;
|
||||
import com.arialyy.aria.core.scheduler.ISchedulers;
|
||||
import java.io.File;
|
||||
@ -33,14 +36,18 @@ public class DownloadTask extends AbsNormalTask<DownloadEntity> {
|
||||
public static final String TAG = "DownloadTask";
|
||||
|
||||
private DownloadListener mListener;
|
||||
private SimpleDownloadUtil mUtil;
|
||||
private IDownloadUtil mUtil;
|
||||
|
||||
private DownloadTask(DownloadTaskEntity taskEntity, Handler outHandler) {
|
||||
mEntity = taskEntity.getEntity();
|
||||
mOutHandler = outHandler;
|
||||
mContext = AriaManager.APP;
|
||||
mListener = new DownloadListener(this, mOutHandler);
|
||||
mUtil = new SimpleDownloadUtil(taskEntity, mListener);
|
||||
if (taskEntity.downloadType == AbsTaskEntity.HTTP) {
|
||||
mUtil = new SimpleDownloadUtil(taskEntity, mListener);
|
||||
}else if (taskEntity.downloadType == AbsTaskEntity.FTP){
|
||||
mUtil = new FtpDownloadUtil(taskEntity, mListener);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -16,6 +16,7 @@
|
||||
package com.arialyy.aria.core.download;
|
||||
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.orm.Ignore;
|
||||
import com.arialyy.aria.orm.OneToOne;
|
||||
|
||||
/**
|
||||
@ -24,6 +25,17 @@ import com.arialyy.aria.orm.OneToOne;
|
||||
*/
|
||||
public class DownloadTaskEntity extends AbsTaskEntity<DownloadEntity> {
|
||||
|
||||
/**
|
||||
* 账号和密码
|
||||
*/
|
||||
@Ignore public String userName, userPw;
|
||||
|
||||
/**
|
||||
* 下载类型
|
||||
* {@link AbsTaskEntity#HTTP}、{@link AbsTaskEntity#FTP}
|
||||
*/
|
||||
public int downloadType = HTTP;
|
||||
|
||||
@OneToOne(table = DownloadEntity.class, key = "downloadPath") public DownloadEntity entity;
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.arialyy.aria.core.download;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
|
||||
/**
|
||||
* Created by lyy on 2016/12/5.
|
||||
* https://github.com/AriaLyy/Aria
|
||||
*/
|
||||
public class FtpDownloadTarget extends DownloadTarget {
|
||||
private final String TAG = "FtpDownloadTarget";
|
||||
|
||||
/**
|
||||
* @param serverIp ftp服务器地址
|
||||
* @param port ftp端口号
|
||||
*/
|
||||
FtpDownloadTarget(String serverIp, String port, String filePath, String targetName) {
|
||||
this(serverIp + ":" + port + "/" + filePath, targetName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param url url 为 serverIp:port/filePath
|
||||
*/
|
||||
private FtpDownloadTarget(String url, String targetName) {
|
||||
super(url, targetName);
|
||||
mTaskEntity.downloadType = AbsTaskEntity.FTP;
|
||||
mTargetName = targetName;
|
||||
}
|
||||
|
||||
/**
|
||||
* ftp 用户登录信息
|
||||
*
|
||||
* @param userName ftp用户名
|
||||
* @param password ftp用户密码
|
||||
*/
|
||||
public FtpDownloadTarget login(String userName, String password) {
|
||||
if (TextUtils.isEmpty(userName)) {
|
||||
Log.e(TAG, "用户名不能为null");
|
||||
return this;
|
||||
} else if (TextUtils.isEmpty(password)) {
|
||||
Log.e(TAG, "密码不能为null");
|
||||
return this;
|
||||
}
|
||||
mTaskEntity.userName = userName;
|
||||
mTaskEntity.userPw = password;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置下载的文件
|
||||
*
|
||||
* @param filePath ftp服务器上的文件
|
||||
*/
|
||||
public FtpDownloadTarget getFile(String filePath) {
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
@ -204,6 +204,10 @@ public class DownloadGroupUtil implements IDownloadUtil {
|
||||
mListener.onResume(mCurrentLocation);
|
||||
}
|
||||
|
||||
@Override public void setMaxSpeed(double maxSpeed) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建文件信息获取线程
|
||||
*/
|
||||
|
@ -1,10 +1,25 @@
|
||||
package com.arialyy.aria.core.download.downloader;
|
||||
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||
import java.io.IOException;
|
||||
import org.apache.commons.net.ftp.FTPClient;
|
||||
import org.apache.commons.net.ftp.FTPReply;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/7/21.
|
||||
*/
|
||||
public class FtpDownloadUtil implements IDownloadUtil, Runnable{
|
||||
|
||||
public class FtpDownloadUtil implements IDownloadUtil, Runnable {
|
||||
|
||||
private IDownloadListener mListener;
|
||||
private DownloadTaskEntity mTaskEntity;
|
||||
private DownloadEntity mEntity;
|
||||
|
||||
public FtpDownloadUtil(DownloadTaskEntity entity, IDownloadListener downloadListener) {
|
||||
mTaskEntity = entity;
|
||||
mListener = downloadListener;
|
||||
mEntity = mTaskEntity.getEntity();
|
||||
}
|
||||
|
||||
@Override public long getFileSize() {
|
||||
return 0;
|
||||
@ -27,14 +42,36 @@ public class FtpDownloadUtil implements IDownloadUtil, Runnable{
|
||||
}
|
||||
|
||||
@Override public void startDownload() {
|
||||
|
||||
mListener.onPre();
|
||||
new Thread(this).start();
|
||||
}
|
||||
|
||||
@Override public void resumeDownload() {
|
||||
|
||||
}
|
||||
|
||||
@Override public void setMaxSpeed(double maxSpeed) {
|
||||
|
||||
}
|
||||
|
||||
@Override public void run() {
|
||||
|
||||
}
|
||||
|
||||
private void failDownload(String msg) {
|
||||
|
||||
}
|
||||
|
||||
private void test() throws IOException {
|
||||
FTPClient client = new FTPClient();
|
||||
client.connect(mEntity.getDownloadUrl());
|
||||
client.login(mTaskEntity.userName, mTaskEntity.userPw);
|
||||
int reply = client.getReplyCode();
|
||||
if (!FTPReply.isPositiveCompletion(reply)) {
|
||||
client.disconnect();
|
||||
failDownload("无法连接到ftp服务器,错误码为:" + reply);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -58,4 +58,9 @@ public interface IDownloadUtil {
|
||||
* 从上次断点恢复下载
|
||||
*/
|
||||
void resumeDownload();
|
||||
|
||||
/**
|
||||
* 设置最大下载速度
|
||||
*/
|
||||
void setMaxSpeed(double maxSpeed);
|
||||
}
|
@ -26,6 +26,8 @@ import java.util.Map;
|
||||
* Created by lyy on 2017/2/23.
|
||||
*/
|
||||
public abstract class AbsTaskEntity<ENTITY extends AbsEntity> extends DbEntity {
|
||||
public static final int HTTP = 0x11;
|
||||
public static final int FTP = 0x12;
|
||||
|
||||
/**
|
||||
* Task实体对应的key
|
||||
|
Reference in New Issue
Block a user