Skip to content
Permalink
Browse files

sftp上传实现

  • Loading branch information
AriaLyy committed Jan 18, 2020
1 parent 50b265f commit d217ebcb254e9c302e6eb47c7290f3944c79bf29
Showing with 1,616 additions and 387 deletions.
  1. +0 −51 Aria/src/main/java/com/arialyy/aria/core/common/FtpOption.java
  2. +135 −0 Aria/src/main/java/com/arialyy/aria/core/common/SFtpOption.java
  3. +2 −1 Aria/src/main/java/com/arialyy/aria/core/download/target/FtpBuilderTarget.java
  4. +2 −1 Aria/src/main/java/com/arialyy/aria/core/download/target/FtpNormalTarget.java
  5. +15 −0 Aria/src/main/java/com/arialyy/aria/core/upload/target/FtpBuilderTarget.java
  6. +15 −0 Aria/src/main/java/com/arialyy/aria/core/upload/target/FtpNormalTarget.java
  7. +4 −1 DEV_LOG.md
  8. +0 −95 FtpComponent/src/main/java/com/arialyy/aria/ftp/download/FtpDLoader.java
  9. +3 −3 FtpComponent/src/main/java/com/arialyy/aria/ftp/download/FtpDRecordHandler.java
  10. +5 −3 FtpComponent/src/main/java/com/arialyy/aria/ftp/upload/FtpULoader.java
  11. +2 −1 FtpComponent/src/main/java/com/arialyy/aria/ftp/upload/FtpULoaderUtil.java
  12. +1 −1 FtpComponent/src/main/java/com/arialyy/aria/ftp/upload/FtpURecordHandler.java
  13. +4 −0 HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDThreadTaskAdapter.java
  14. +1 −1 HttpComponent/src/main/java/com/arialyy/aria/http/upload/HttpULoader.java
  15. +2 −2 M3U8Component/src/main/java/com/arialyy/aria/m3u8/BaseM3U8Loader.java
  16. +1 −1 M3U8Component/src/main/java/com/arialyy/aria/m3u8/M3U8InfoTask.java
  17. +5 −2 M3U8Component/src/main/java/com/arialyy/aria/m3u8/M3U8ThreadTaskAdapter.java
  18. +4 −4 PublicComponent/src/main/java/com/arialyy/aria/core/loader/AbsNormalLoader.java
  19. +2 −2 PublicComponent/src/main/java/com/arialyy/aria/core/loader/NormalLoader.java
  20. +27 −8 PublicComponent/src/main/java/com/arialyy/aria/core/loader/NormalThreadStateManager.java
  21. +2 −1 PublicComponent/src/main/java/com/arialyy/aria/core/processor/IKeyUrlConverter.java
  22. +6 −0 PublicComponent/src/main/java/com/arialyy/aria/core/task/ThreadTask.java
  23. +5 −0 PublicComponent/src/main/java/com/arialyy/aria/core/wrapper/ITaskWrapper.java
  24. +12 −2 PublicComponent/src/main/java/com/arialyy/aria/util/CommonUtil.java
  25. +9 −0 PublicComponent/src/main/java/com/arialyy/aria/util/ComponentUtil.java
  26. +8 −23 PublicComponent/src/main/java/com/arialyy/aria/util/FileUtil.java
  27. +16 −16 README.md
  28. +11 −0 SFtpComponent/bintray-release.gradle
  29. +4 −3 SFtpComponent/build.gradle
  30. +3 −4 SFtpComponent/src/main/java/com/arialyy/aria/sftp/AbsSFtpInfoTask.java
  31. +1 −1 SFtpComponent/src/main/java/com/arialyy/aria/sftp/SFtpSessionManager.java
  32. +21 −2 SFtpComponent/src/main/java/com/arialyy/aria/sftp/{SFtpSubThreadCOnfig.java → SFtpTaskOption.java}
  33. +3 −3 SFtpComponent/src/main/java/com/arialyy/aria/sftp/SFtpUtil.java
  34. +21 −8 SFtpComponent/src/main/java/com/arialyy/aria/sftp/download/SFtpDInfoTask.java
  35. +6 −7 SFtpComponent/src/main/java/com/arialyy/aria/sftp/download/SFtpDLoader.java
  36. +5 −5 SFtpComponent/src/main/java/com/arialyy/aria/sftp/download/SFtpDLoaderUtil.java
  37. +92 −0 SFtpComponent/src/main/java/com/arialyy/aria/sftp/download/SFtpDRecordHandler.java
  38. +5 −4 SFtpComponent/src/main/java/com/arialyy/aria/sftp/download/SFtpDTTBuilderAdapter.java
  39. +62 −88 SFtpComponent/src/main/java/com/arialyy/aria/sftp/download/SFtpDThreadTaskAdapter.java
  40. +69 −0 SFtpComponent/src/main/java/com/arialyy/aria/sftp/upload/SFtpUInfoTask.java
  41. +155 −0 SFtpComponent/src/main/java/com/arialyy/aria/sftp/upload/SFtpULoader.java
  42. +55 −0 SFtpComponent/src/main/java/com/arialyy/aria/sftp/upload/SFtpULoaderUtil.java
  43. +115 −0 SFtpComponent/src/main/java/com/arialyy/aria/sftp/upload/SFtpURecordHandler.java
  44. +73 −0 SFtpComponent/src/main/java/com/arialyy/aria/sftp/upload/SFtpUTTBuilderAdapter.java
  45. +201 −0 SFtpComponent/src/main/java/com/arialyy/aria/sftp/upload/SFtpUThreadTaskAdapter.java
  46. +28 −27 app/src/main/AndroidManifest.xml
  47. +1 −1 app/src/main/assets/aria_config.xml
  48. +6 −1 app/src/main/java/com/arialyy/simple/MainActivity.java
  49. +3 −4 app/src/main/java/com/arialyy/simple/core/download/SFtpDownloadActivity.java
  50. +1 −0 app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java
  51. +19 −2 app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8VodDLoadActivity.java
  52. +1 −1 app/src/main/java/com/arialyy/simple/core/upload/FtpUploadActivity.java
  53. +239 −0 app/src/main/java/com/arialyy/simple/core/upload/SFtpUploadActivity.java
  54. +25 −0 app/src/main/java/com/arialyy/simple/core/upload/UploadModule.java
  55. +1 −0 app/src/main/java/com/arialyy/simple/modlue/CommonModule.java
  56. +15 −5 app/src/main/res/layout/activity_m3u8_vod.xml
  57. +83 −0 app/src/main/res/layout/activity_sftp_upload.xml
  58. +2 −0 app/src/main/res/values/strings.xml
  59. +2 −2 build.gradle
@@ -141,57 +141,6 @@ public FtpOption setStorePath(String storePath) {
return this;
}

/**
* 设置私钥证书路径
*
* @param prvKey 证书路径
*/
public FtpOption setPrvKey(String prvKey) {
if (TextUtils.isEmpty(prvKey)) {
ALog.e(TAG, "设置私钥证书失败,证书内容为空");
return this;
}
idEntity.prvKey = prvKey;
return this;
}

/**
* 设置私钥密码
*
* @param prvKeyPass 私钥密码
*/
public FtpOption setPrvKeyPass(String prvKeyPass) {
if (TextUtils.isEmpty(prvKeyPass)) {
ALog.e(TAG, "设置证书密码失败,证书密码为空");
return this;
}
idEntity.prvPass = prvKeyPass;
return this;
}

/**
* 设置公钥证书
*
* @param pubKey 公钥证书内容
*/
public FtpOption setPubKey(String pubKey) {
if (TextUtils.isEmpty(pubKey)) {
ALog.e(TAG, "设置公钥失败,证书内容为空");
return this;
}
idEntity.pubKey = pubKey;
return this;
}

public FtpOption setKnowHostPath(String knowHostPath){
if (TextUtils.isEmpty(knowHostPath)){
ALog.e(TAG, "knowhost 文件路径为空");
return this;
}
idEntity.knowHost = knowHostPath;
return this;
}

/**
* 设置安全模式,默认true
*
@@ -0,0 +1,135 @@
/*
* 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.common;

import android.text.TextUtils;
import com.arialyy.aria.core.FtpUrlEntity;
import com.arialyy.aria.core.IdEntity;
import com.arialyy.aria.core.ProtocolType;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.ComponentUtil;

/**
* Created by laoyuyu on 2018/3/9.
*/
public class SFtpOption extends BaseOption {

private String charSet, userName, password;
private boolean isNeedLogin = false;
private FtpUrlEntity urlEntity;
private String protocol;
private IdEntity idEntity = new IdEntity();

public SFtpOption() {
super();
ComponentUtil.getInstance().checkComponentExist(ComponentUtil.COMPONENT_TYPE_M3U8);
}

public SFtpOption charSet(String charSet) {
if (TextUtils.isEmpty(charSet)) {
throw new NullPointerException("字符编码为空");
}
this.charSet = charSet;
return this;
}

public SFtpOption login(String userName, String password) {
if (TextUtils.isEmpty(userName)) {
ALog.e(TAG, "用户名不能为null");
return this;
} else if (TextUtils.isEmpty(password)) {
ALog.e(TAG, "密码不能为null");
return this;
}
this.userName = userName;
this.password = password;
isNeedLogin = true;
return this;
}

/**
* 设置协议类型
*
* @param protocol {@link ProtocolType}
*/
public SFtpOption setProtocol(String protocol) {
if (TextUtils.isEmpty(protocol)) {
ALog.e(TAG, "设置协议失败,协议信息为空");
return this;
}
this.protocol = protocol;
return this;
}

/**
* 设置私钥证书路径
*
* @param prvKey 证书路径
*/
public SFtpOption setPrvKey(String prvKey) {
if (TextUtils.isEmpty(prvKey)) {
ALog.e(TAG, "设置私钥证书失败,证书内容为空");
return this;
}
idEntity.prvKey = prvKey;
return this;
}

/**
* 设置私钥密码
*
* @param prvKeyPass 私钥密码
*/
public SFtpOption setPrvKeyPass(String prvKeyPass) {
if (TextUtils.isEmpty(prvKeyPass)) {
ALog.e(TAG, "设置证书密码失败,证书密码为空");
return this;
}
idEntity.prvPass = prvKeyPass;
return this;
}

/**
* 设置公钥证书
*
* @param pubKey 公钥证书内容
*/
public SFtpOption setPubKey(String pubKey) {
if (TextUtils.isEmpty(pubKey)) {
ALog.e(TAG, "设置公钥失败,证书内容为空");
return this;
}
idEntity.pubKey = pubKey;
return this;
}

public SFtpOption setKnowHostPath(String knowHostPath) {
if (TextUtils.isEmpty(knowHostPath)) {
ALog.e(TAG, "knowhost 文件路径为空");
return this;
}
idEntity.knowHost = knowHostPath;
return this;
}

public void setUrlEntity(FtpUrlEntity urlEntity) {
this.urlEntity = urlEntity;
urlEntity.needLogin = isNeedLogin;
urlEntity.user = userName;
urlEntity.password = password;
urlEntity.idEntity = idEntity;
}
}
@@ -17,6 +17,7 @@

import com.arialyy.aria.core.common.AbsBuilderTarget;
import com.arialyy.aria.core.common.FtpOption;
import com.arialyy.aria.core.common.SFtpOption;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.wrapper.ITaskWrapper;
import com.arialyy.aria.util.CommonUtil;
@@ -50,7 +51,7 @@ public FtpBuilderTarget option(FtpOption option) {
/**
* 设置登陆、字符串编码、sftp等参数
*/
public FtpBuilderTarget sftpOption(FtpOption option) {
public FtpBuilderTarget sftpOption(SFtpOption option) {
if (option == null) {
throw new NullPointerException("ftp 任务配置为空");
}
@@ -17,6 +17,7 @@

import com.arialyy.aria.core.common.AbsNormalTarget;
import com.arialyy.aria.core.common.FtpOption;
import com.arialyy.aria.core.common.SFtpOption;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.wrapper.ITaskWrapper;
import com.arialyy.aria.util.CommonUtil;
@@ -49,7 +50,7 @@ public FtpNormalTarget option(FtpOption option) {
/**
* 设置登陆、字符串编码、sftp等参数
*/
public FtpNormalTarget sftpOption(FtpOption option) {
public FtpNormalTarget sftpOption(SFtpOption option) {
if (option == null) {
throw new NullPointerException("ftp 任务配置为空");
}
@@ -17,6 +17,7 @@

import com.arialyy.aria.core.common.AbsBuilderTarget;
import com.arialyy.aria.core.common.FtpOption;
import com.arialyy.aria.core.common.SFtpOption;
import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.core.wrapper.ITaskWrapper;
import com.arialyy.aria.util.CommonUtil;
@@ -70,4 +71,18 @@ public FtpBuilderTarget option(FtpOption option) {
getTaskWrapper().getOptionParams().setParams(option);
return this;
}

/**
* 设置登陆、字符串编码、sftp等参数
*/
public FtpBuilderTarget sftpOption(SFtpOption option) {
if (option == null) {
throw new NullPointerException("ftp 任务配置为空");
}
option.setUrlEntity(CommonUtil.getFtpUrlInfo(url));
getTaskWrapper().getOptionParams().setParams(option);
((UploadEntity)getEntity()).setTaskType(ITaskWrapper.U_SFTP);
getTaskWrapper().setRequestType(ITaskWrapper.U_SFTP);
return this;
}
}
@@ -17,6 +17,7 @@

import com.arialyy.aria.core.common.AbsNormalTarget;
import com.arialyy.aria.core.common.FtpOption;
import com.arialyy.aria.core.common.SFtpOption;
import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.core.wrapper.ITaskWrapper;
import com.arialyy.aria.util.CommonUtil;
@@ -46,6 +47,20 @@ public FtpNormalTarget option(FtpOption option) {
return this;
}

/**
* 设置登陆、字符串编码、sftp等参数
*/
public FtpNormalTarget sftpOption(SFtpOption option) {
if (option == null) {
throw new NullPointerException("ftp 任务配置为空");
}
option.setUrlEntity(CommonUtil.getFtpUrlInfo(getEntity().getUrl()));
getTaskWrapper().getOptionParams().setParams(option);
(getEntity()).setTaskType(ITaskWrapper.U_SFTP);
getTaskWrapper().setRequestType(ITaskWrapper.U_SFTP);
return this;
}

@Override public UploadEntity getEntity() {
return (UploadEntity) super.getEntity();
}
@@ -1,6 +1,9 @@
## 开发日志
+ v_3.8.4
+ v_3.8.5 (2020/1/18)
- fix bug https://github.com/AriaLyy/Aria/issues/599
- 增加密钥url转换器的参数 https://github.com/AriaLyy/Aria/issues/603
- 增加sftp,文件上传、下载功能,[sftp下载](https://aria.laoyuyu.me/aria_doc/download/sftp_normal.html),[sftp上传](https://aria.laoyuyu.me/aria_doc/upload/sftp_normal.html)
- 使用零拷贝技术,优化了合并分块的效率
+ v_3.8.3 (2020/1/9)
- fix bug https://github.com/AriaLyy/Aria/issues/573
- android P适配 https://github.com/AriaLyy/Aria/issues/581

This file was deleted.

0 comments on commit d217ebc

Please sign in to comment.
You can’t perform that action at this time.