!653 【添加】sftp add refactoring method

Merge pull request !653 from 不忘初心/v5-dev
This commit is contained in:
Looly 2022-06-12 13:41:03 +00:00 committed by Gitee
commit 895a1448cf
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 56 additions and 2 deletions

View File

@ -114,9 +114,24 @@ public class JschUtil {
* @return SSH会话
*/
public static Session openSession(String sshHost, int sshPort, String sshUser, String privateKeyPath, byte[] passphrase) {
return openSession(sshHost, sshPort, sshUser, privateKeyPath, passphrase, 0);
}
/**
* 打开一个新的SSH会话
*
* @param sshHost 主机
* @param sshPort 端口
* @param sshUser 用户名
* @param privateKeyPath 私钥的路径
* @param passphrase 私钥文件的密码可以为null
* @param timeOut 超时时间单位毫秒
* @return SSH会话
*/
public static Session openSession(String sshHost, int sshPort, String sshUser, String privateKeyPath, byte[] passphrase, int timeOut) {
final Session session = createSession(sshHost, sshPort, sshUser, privateKeyPath, passphrase);
try {
session.connect();
session.connect(timeOut);
} catch (JSchException e) {
throw new JschRuntimeException(e);
}

View File

@ -77,8 +77,21 @@ public class Sftp extends AbstractFtp {
* @since 5.3.3
*/
public Sftp(FtpConfig config) {
this(config, true);
}
/**
* 构造
*
* @param config FTP配置
* @param init 是否立即初始化
* @since 5.8.4
*/
public Sftp(FtpConfig config, boolean init) {
super(config);
init(config);
if (init) {
init(config);
}
}
/**
@ -102,6 +115,32 @@ public class Sftp extends AbstractFtp {
init(session, charset);
}
/**
* 构造
*
* @param session {@link Session}
* @param charset 编码
* @param timeOut 超时时间单位毫秒
* @since 5.8.4
*/
public Sftp(Session session, Charset charset, long timeOut) {
super(FtpConfig.create().setCharset(charset).setConnectionTimeout(timeOut));
init(session, charset);
}
/**
* 构造
*
* @param channel {@link ChannelSftp}
* @param charset 编码
* @param timeOut 超时时间单位毫秒
* @since 5.8.4
*/
public Sftp(ChannelSftp channel, Charset charset, long timeOut) {
super(FtpConfig.create().setCharset(charset).setConnectionTimeout(timeOut));
init(channel, charset);
}
/**
* 构造
*