pull/617/head
parent
e8c5a9f08b
commit
c1b1cc1390
@ -1,3 +0,0 @@ |
||||
<resources> |
||||
<string name="app_name">AriaFtpComponent</string> |
||||
</resources> |
@ -1,3 +0,0 @@ |
||||
<resources> |
||||
<string name="app_name">HttpComponent</string> |
||||
</resources> |
@ -1,3 +0,0 @@ |
||||
<resources> |
||||
<string name="app_name">M3U8Component</string> |
||||
</resources> |
@ -1,3 +0,0 @@ |
||||
<resources> |
||||
<string name="app_name">PublicComponent</string> |
||||
</resources> |
@ -0,0 +1 @@ |
||||
/build |
@ -0,0 +1,33 @@ |
||||
apply plugin: 'com.android.library' |
||||
|
||||
android { |
||||
compileSdkVersion rootProject.ext.compileSdkVersion |
||||
buildToolsVersion rootProject.ext.buildToolsVersion |
||||
|
||||
defaultConfig { |
||||
minSdkVersion rootProject.ext.minSdkVersion |
||||
targetSdkVersion rootProject.ext.targetSdkVersion |
||||
versionCode rootProject.ext.versionCode |
||||
versionName rootProject.ext.versionName |
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" |
||||
consumerProguardFiles 'consumer-rules.pro' |
||||
} |
||||
|
||||
buildTypes { |
||||
release { |
||||
minifyEnabled false |
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' |
||||
} |
||||
} |
||||
} |
||||
|
||||
dependencies { |
||||
implementation fileTree(dir: 'libs', include: ['*.jar']) |
||||
|
||||
implementation "androidx.appcompat:appcompat:${rootProject.ext.XAppcompatVersion}" |
||||
implementation "com.jcraft:jsch:0.1.55" |
||||
implementation "com.jcraft:jzlib:1.1.3" |
||||
implementation project(path: ':FtpComponent') |
||||
compile project(path: ':PublicComponent') |
||||
} |
@ -0,0 +1,21 @@ |
||||
# Add project specific ProGuard rules here. |
||||
# You can control the set of applied configuration files using the |
||||
# proguardFiles setting in build.gradle. |
||||
# |
||||
# For more details, see |
||||
# http://developer.android.com/guide/developing/tools/proguard.html |
||||
|
||||
# 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,2 @@ |
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" |
||||
package="com.arialyy.aria.sftp" /> |
@ -0,0 +1,58 @@ |
||||
/* |
||||
* 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.sftp; |
||||
|
||||
import com.arialyy.aria.core.AriaConfig; |
||||
import com.arialyy.aria.core.common.AbsEntity; |
||||
import com.arialyy.aria.core.inf.OnFileInfoCallback; |
||||
import com.arialyy.aria.core.upload.UploadEntity; |
||||
import com.arialyy.aria.core.wrapper.AbsTaskWrapper; |
||||
import com.arialyy.aria.ftp.FtpTaskOption; |
||||
import com.arialyy.aria.util.CommonUtil; |
||||
|
||||
/** |
||||
* |
||||
* https://cloud.tencent.com/developer/article/1354612
|
||||
* @author lyy |
||||
*/ |
||||
public class AbsSFtpInfoThread<ENTITY extends AbsEntity, TASK_WRAPPER extends AbsTaskWrapper<ENTITY>> |
||||
implements Runnable { |
||||
|
||||
private final String TAG = CommonUtil.getClassName(getClass()); |
||||
protected ENTITY mEntity; |
||||
protected TASK_WRAPPER mTaskWrapper; |
||||
protected FtpTaskOption mTaskOption; |
||||
private int mConnectTimeOut; |
||||
protected OnFileInfoCallback mCallback; |
||||
protected long mSize = 0; |
||||
protected String charSet = "UTF-8"; |
||||
private boolean isUpload = false; |
||||
|
||||
public AbsSFtpInfoThread(TASK_WRAPPER taskWrapper, OnFileInfoCallback callback) { |
||||
mTaskWrapper = taskWrapper; |
||||
mEntity = taskWrapper.getEntity(); |
||||
mTaskOption = (FtpTaskOption) taskWrapper.getTaskOption(); |
||||
mConnectTimeOut = AriaConfig.getInstance().getDConfig().getConnectTimeOut(); |
||||
mCallback = callback; |
||||
if (mEntity instanceof UploadEntity) { |
||||
isUpload = true; |
||||
} |
||||
} |
||||
|
||||
@Override public void run() { |
||||
|
||||
} |
||||
} |
@ -0,0 +1,125 @@ |
||||
/* |
||||
* 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.sftp; |
||||
|
||||
import android.text.TextUtils; |
||||
import com.jcraft.jsch.JSch; |
||||
import com.jcraft.jsch.JSchException; |
||||
import com.jcraft.jsch.Session; |
||||
import java.util.Properties; |
||||
|
||||
/** |
||||
* sftp登录 |
||||
* |
||||
* @author lyy |
||||
*/ |
||||
public class SFtpLogin { |
||||
|
||||
private String ip, userName, password; |
||||
private int port; |
||||
private Session session; |
||||
private boolean isLogin = false; |
||||
|
||||
private SFtpLogin() { |
||||
createClient(); |
||||
} |
||||
|
||||
/** |
||||
* 创建客户端 |
||||
*/ |
||||
private void createClient() { |
||||
JSch jSch = new JSch(); |
||||
try { |
||||
if (TextUtils.isEmpty(userName)) { |
||||
session = jSch.getSession(userName, ip, port); |
||||
} else { |
||||
session = jSch.getSession(ip); |
||||
} |
||||
if (!TextUtils.isEmpty(password)) { |
||||
session.setPassword(password); |
||||
} |
||||
Properties config = new Properties(); |
||||
config.put("StrictHostKeyChecking", "no"); |
||||
session.setConfig(config);// 为Session对象设置properties
|
||||
session.setTimeout(3000);// 设置超时
|
||||
isLogin = true; |
||||
} catch (JSchException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 执行登录 |
||||
*/ |
||||
public Session login() { |
||||
try { |
||||
session.connect(); // 通过Session建立连接
|
||||
} catch (JSchException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
return session; |
||||
} |
||||
|
||||
/** |
||||
* 登出 |
||||
*/ |
||||
public void logout() { |
||||
if (session != null) { |
||||
session.disconnect(); |
||||
} |
||||
isLogin = false; |
||||
} |
||||
|
||||
public static class Builder { |
||||
private String ip, userName, password; |
||||
private int port = 22; |
||||
|
||||
public Builder setIp(String ip) { |
||||
this.ip = ip; |
||||
return this; |
||||
} |
||||
|
||||
public Builder setUserName(String userName) { |
||||
this.userName = userName; |
||||
return this; |
||||
} |
||||
|
||||
public Builder setPassword(String password) { |
||||
this.password = password; |
||||
return this; |
||||
} |
||||
|
||||
public Builder setPort(int port) { |
||||
this.port = port; |
||||
return this; |
||||
} |
||||
|
||||
public SFtpLogin build() { |
||||
SFtpLogin login = new SFtpLogin(); |
||||
login.ip = ip; |
||||
login.userName = userName; |
||||
login.password = password; |
||||
login.port = port; |
||||
if (TextUtils.isEmpty(ip)) { |
||||
throw new IllegalArgumentException("ip不能为空"); |
||||
} |
||||
if (port < 0 || port > 65534) { |
||||
throw new IllegalArgumentException("端口错误"); |
||||
} |
||||
return login; |
||||
} |
||||
} |
||||
} |
@ -1,2 +1,2 @@ |
||||
include ':app', ':Aria', ':AriaAnnotations', ':AriaCompiler', ':AriaFtpPlug', ':AppFrame', ':HttpComponent', ':M3U8Component', |
||||
include ':app', ':Aria', ':AriaAnnotations', ':AriaCompiler', ':AriaFtpPlug', ':AppFrame', ':HttpComponent', ':M3U8Component', ':SFtpComponent', |
||||
':FtpComponent', ':PublicComponent' |
||||
|
Loading…
Reference in new issue