mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
add methodsa
This commit is contained in:
parent
b958833f77
commit
a947d2171e
@ -96,6 +96,7 @@ public class JschUtil {
|
||||
public static Session openSession(final String sshHost, final int sshPort, final String sshUser, final String sshPass, final int timeout) {
|
||||
final Session session = createSession(sshHost, sshPort, sshUser, sshPass);
|
||||
try {
|
||||
session.setTimeout(timeout);
|
||||
session.connect(timeout);
|
||||
} catch (final JSchException e) {
|
||||
throw new JschRuntimeException(e);
|
||||
@ -123,6 +124,28 @@ public class JschUtil {
|
||||
return session;
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开一个新的SSH会话
|
||||
*
|
||||
* @param sshHost 主机
|
||||
* @param sshPort 端口
|
||||
* @param sshUser 用户名
|
||||
* @param privateKeyPath 私钥的路径
|
||||
* @param passphrase 私钥文件的密码,可以为null
|
||||
* @param timeout 超时时间,单位毫秒
|
||||
* @return SSH会话
|
||||
*/
|
||||
public static Session openSession(final String sshHost, final int sshPort, final String sshUser, final String privateKeyPath, final byte[] passphrase, final int timeout) {
|
||||
final Session session = createSession(sshHost, sshPort, sshUser, privateKeyPath, passphrase);
|
||||
try {
|
||||
session.setTimeout(timeout);
|
||||
session.connect(timeout);
|
||||
} catch (final JSchException e) {
|
||||
throw new JschRuntimeException(e);
|
||||
}
|
||||
return session;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建一个新的SSH会话,此方法并不打开会话(既不调用connect方法)
|
||||
*
|
||||
|
@ -31,7 +31,7 @@ import java.util.Vector;
|
||||
*
|
||||
* <p>
|
||||
* 此类为基于jsch的SFTP实现<br>
|
||||
* 参考:https://www.cnblogs.com/longyg/archive/2012/06/25/2556576.html
|
||||
* 参考:<a href="https://www.cnblogs.com/longyg/archive/2012/06/25/2556576.html">https://www.cnblogs.com/longyg/archive/2012/06/25/2556576.html</a>
|
||||
* </p>
|
||||
*
|
||||
* @author looly
|
||||
@ -77,8 +77,21 @@ public class Sftp extends AbstractFtp {
|
||||
* @since 5.3.3
|
||||
*/
|
||||
public Sftp(final FtpConfig config) {
|
||||
this(config, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param config FTP配置
|
||||
* @param init 是否立即初始化
|
||||
* @since 5.8.4
|
||||
*/
|
||||
public Sftp(final FtpConfig config, final boolean init) {
|
||||
super(config);
|
||||
init(config);
|
||||
if (init) {
|
||||
init(config);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -112,6 +125,32 @@ public class Sftp extends AbstractFtp {
|
||||
super(FtpConfig.create().setCharset(charset));
|
||||
init(channel, charset);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param session {@link Session}
|
||||
* @param charset 编码
|
||||
* @param timeOut 超时时间,单位毫秒
|
||||
* @since 5.8.4
|
||||
*/
|
||||
public Sftp(final Session session, final Charset charset, final 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(final ChannelSftp channel, final Charset charset, final long timeOut) {
|
||||
super(FtpConfig.create().setCharset(charset).setConnectionTimeout(timeOut));
|
||||
init(channel, charset);
|
||||
}
|
||||
// ---------------------------------------------------------------------------------------- Constructor end
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user