mirror of
https://gitee.com/dromara/hutool.git
synced 2025-05-16 21:19:35 +08:00
sftp add refactoring method
This commit is contained in:
parent
77818aa376
commit
3ab1c45228
@ -114,9 +114,24 @@ public class JschUtil {
|
|||||||
* @return SSH会话
|
* @return SSH会话
|
||||||
*/
|
*/
|
||||||
public static Session openSession(String sshHost, int sshPort, String sshUser, String privateKeyPath, byte[] passphrase) {
|
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);
|
final Session session = createSession(sshHost, sshPort, sshUser, privateKeyPath, passphrase);
|
||||||
try {
|
try {
|
||||||
session.connect();
|
session.connect(timeOut);
|
||||||
} catch (JSchException e) {
|
} catch (JSchException e) {
|
||||||
throw new JschRuntimeException(e);
|
throw new JschRuntimeException(e);
|
||||||
}
|
}
|
||||||
|
@ -77,8 +77,21 @@ public class Sftp extends AbstractFtp {
|
|||||||
* @since 5.3.3
|
* @since 5.3.3
|
||||||
*/
|
*/
|
||||||
public Sftp(FtpConfig config) {
|
public Sftp(FtpConfig config) {
|
||||||
|
this(config, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造
|
||||||
|
*
|
||||||
|
* @param config FTP配置
|
||||||
|
* @param init 是否立即初始化
|
||||||
|
* @since 5.8.4
|
||||||
|
*/
|
||||||
|
public Sftp(FtpConfig config, boolean init) {
|
||||||
super(config);
|
super(config);
|
||||||
init(config);
|
if (init) {
|
||||||
|
init(config);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -102,6 +115,32 @@ public class Sftp extends AbstractFtp {
|
|||||||
init(session, charset);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构造
|
* 构造
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user