sftp上传实现
This commit is contained in:
@@ -141,57 +141,6 @@ public class FtpOption extends BaseOption {
|
||||
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
|
||||
*
|
||||
|
||||
135
Aria/src/main/java/com/arialyy/aria/core/common/SFtpOption.java
Normal file
135
Aria/src/main/java/com/arialyy/aria/core/common/SFtpOption.java
Normal file
@@ -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 @@ package com.arialyy.aria.core.download.target;
|
||||
|
||||
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 class FtpBuilderTarget extends AbsBuilderTarget<FtpBuilderTarget> {
|
||||
/**
|
||||
* 设置登陆、字符串编码、sftp等参数
|
||||
*/
|
||||
public FtpBuilderTarget sftpOption(FtpOption option) {
|
||||
public FtpBuilderTarget sftpOption(SFtpOption option) {
|
||||
if (option == null) {
|
||||
throw new NullPointerException("ftp 任务配置为空");
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.arialyy.aria.core.download.target;
|
||||
|
||||
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 class FtpNormalTarget extends AbsNormalTarget<FtpNormalTarget> {
|
||||
/**
|
||||
* 设置登陆、字符串编码、sftp等参数
|
||||
*/
|
||||
public FtpNormalTarget sftpOption(FtpOption option) {
|
||||
public FtpNormalTarget sftpOption(SFtpOption option) {
|
||||
if (option == null) {
|
||||
throw new NullPointerException("ftp 任务配置为空");
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.arialyy.aria.core.upload.target;
|
||||
|
||||
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 class FtpBuilderTarget extends AbsBuilderTarget<FtpBuilderTarget> {
|
||||
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 @@ package com.arialyy.aria.core.upload.target;
|
||||
|
||||
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 class FtpNormalTarget extends AbsNormalTarget<FtpNormalTarget> {
|
||||
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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user