Permalink
Browse files

ftp

  • Loading branch information...
AriaLyy committed Jul 24, 2017
1 parent 4f1412b commit 0960d5c6b61d7b2e96ed469e699df35af70e322a
Showing with 20,748 additions and 7 deletions.
  1. +1 −0 Aria/build.gradle
  2. +12 −1 Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java
  3. +9 −2 Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java
  4. +12 −0 Aria/src/main/java/com/arialyy/aria/core/download/DownloadTaskEntity.java
  5. +74 −0 Aria/src/main/java/com/arialyy/aria/core/download/FtpDownloadTarget.java
  6. +4 −0 Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java
  7. +40 −3 Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpDownloadUtil.java
  8. +5 −0 Aria/src/main/java/com/arialyy/aria/core/download/downloader/IDownloadUtil.java
  9. +2 −0 Aria/src/main/java/com/arialyy/aria/core/inf/AbsTaskEntity.java
  10. +1 −0 AriaFtpPlug/.gitignore
  11. +25 −0 AriaFtpPlug/build.gradle
  12. +25 −0 AriaFtpPlug/proguard-rules.pro
  13. +24 −0 AriaFtpPlug/src/androidTest/java/com/arialyy/ftpplug/ExampleInstrumentedTest.java
  14. +12 −0 AriaFtpPlug/src/main/AndroidManifest.xml
  15. +8 −0 AriaFtpPlug/src/main/java/com/arialyy/ftpplug/Test.java
  16. +314 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/DatagramSocketClient.java
  17. +69 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/DatagramSocketFactory.java
  18. +79 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/DefaultDatagramSocketFactory.java
  19. +230 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/DefaultSocketFactory.java
  20. +56 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/MalformedServerReplyException.java
  21. +202 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/PrintCommandListener.java
  22. +148 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/ProtocolCommandEvent.java
  23. +58 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/ProtocolCommandListener.java
  24. +135 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/ProtocolCommandSupport.java
  25. +887 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/SocketClient.java
  26. +35 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/ftp/Configurable.java
  27. +1,870 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/ftp/FTP.java
  28. +3,980 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/ftp/FTPClient.java
  29. +709 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/ftp/FTPClientConfig.java
  30. +116 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/ftp/FTPCmd.java
  31. +171 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/ftp/FTPCommand.java
  32. +55 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/ftp/FTPConnectionClosedException.java
  33. +536 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/ftp/FTPFile.java
  34. +134 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/ftp/FTPFileEntryParser.java
  35. +79 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/ftp/FTPFileEntryParserImpl.java
  36. +33 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/ftp/FTPFileFilter.java
  37. +57 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/ftp/FTPFileFilters.java
  38. +202 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/ftp/FTPHTTPClient.java
  39. +329 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/ftp/FTPListParseEngine.java
  40. +201 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/ftp/FTPReply.java
  41. +925 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/ftp/FTPSClient.java
  42. +52 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/ftp/FTPSCommand.java
  43. +74 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/ftp/FTPSServerSocketFactory.java
  44. +112 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/ftp/FTPSSocketFactory.java
  45. +60 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/ftp/FTPSTrustManager.java
  46. +21 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/ftp/package-info.java
  47. +69 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/ftp/parser/CompositeFileEntryParser.java
  48. +128 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/ftp/parser/ConfigurableFTPFileEntryParserImpl.java
  49. +295 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/ftp/parser/DefaultFTPFileEntryParserFactory.java
  50. +166 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/ftp/parser/EnterpriseUnixFTPEntryParser.java
  51. +68 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/ftp/parser/FTPFileEntryParserFactory.java
  52. +52 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/ftp/parser/FTPTimestampParser.java
  53. +406 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImpl.java
  54. +269 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/ftp/parser/MLSxEntryParser.java
  55. +554 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/ftp/parser/MVSFTPEntryParser.java
  56. +278 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/ftp/parser/MacOsPeterFTPEntryParser.java
  57. +167 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/ftp/parser/NTFTPEntryParser.java
  58. +177 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/ftp/parser/NetwareFTPEntryParser.java
  59. +146 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/ftp/parser/OS2FTPEntryParser.java
  60. +435 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/ftp/parser/OS400FTPEntryParser.java
  61. +62 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/ftp/parser/ParserInitializationException.java
  62. +202 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/ftp/parser/RegexFTPFileEntryParserImpl.java
  63. +379 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/ftp/parser/UnixFTPEntryParser.java
  64. +275 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/ftp/parser/VMSFTPEntryParser.java
  65. +167 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/ftp/parser/VMSVersioningFTPEntryParser.java
  66. +21 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/ftp/parser/package-info.java
  67. +77 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/io/CRLFLineReader.java
  68. +118 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/io/CopyStreamAdapter.java
  69. +111 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/io/CopyStreamEvent.java
  70. +71 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/io/CopyStreamException.java
  71. +69 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/io/CopyStreamListener.java
  72. +251 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/io/DotTerminatedMessageReader.java
  73. +219 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/io/DotTerminatedMessageWriter.java
  74. +221 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/io/FromNetASCIIInputStream.java
  75. +175 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/io/FromNetASCIIOutputStream.java
  76. +68 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/io/SocketInputStream.java
  77. +88 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/io/SocketOutputStream.java
  78. +185 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/io/ToNetASCIIInputStream.java
  79. +120 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/io/ToNetASCIIOutputStream.java
  80. +390 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/io/Util.java
  81. +21 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/io/package-info.java
  82. +1,046 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/util/Base64.java
  83. +54 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/util/Charsets.java
  84. +246 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/util/KeyManagerUtils.java
  85. +66 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/util/ListenerList.java
  86. +73 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/util/SSLContextUtils.java
  87. +63 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/util/SSLSocketUtils.java
  88. +362 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/util/SubnetUtils.java
  89. +117 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/util/TrustManagerUtils.java
  90. +21 −0 AriaFtpPlug/src/main/java/org/apache/commons/net/util/package-info.java
  91. +16 −0 AriaFtpPlug/src/test/java/com/arialyy/ftpplug/ExampleUnitTest.java
  92. +1 −1 settings.gradle
@@ -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 DownloadTarget load(DownloadEntity entity) {
}
/**
* 加载下载地址
* 加载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 @@
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 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 @@
*/
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 @@ private void delDownloadInfo() {
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 @@
}
@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 @@
* 从上次断点恢复下载
*/
void resumeDownload();
/**
* 设置最大下载速度
*/
void setMaxSpeed(double maxSpeed);
}
@@ -26,6 +26,8 @@
* 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
@@ -0,0 +1 @@
/build
@@ -0,0 +1,25 @@
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion '25.0.3'
defaultConfig {
minSdkVersion 9
targetSdkVersion 23
versionCode 327
versionName "3.2.7"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
}
@@ -0,0 +1,25 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in E:\sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
@@ -0,0 +1,24 @@
package com.arialyy.ftpplug;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumentation test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class) public class ExampleInstrumentedTest {
@Test public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("com.arialyy.ftpplug.test", appContext.getPackageName());
}
}
@@ -0,0 +1,12 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.arialyy.ftpplug"
>
<application
android:allowBackup="true"
android:supportsRtl="true"
>
</application>
</manifest>
@@ -0,0 +1,8 @@
package com.arialyy.ftpplug;
/**
* Created by Aria.Lao on 2017/7/24.
*/
public class Test {
}
Oops, something went wrong.

0 comments on commit 0960d5c

Please sign in to comment.