| Constructor and Description |
|---|
JschSession(Connector connector)
构造
|
JschSession(com.jcraft.jsch.Session raw,
long timeout)
构造
|
| Modifier and Type | Method and Description |
|---|---|
void |
bindLocalPort(InetSocketAddress localAddress,
InetSocketAddress remoteAddress)
绑定端口到本地。
|
void |
bindRemotePort(InetSocketAddress remoteAddress,
InetSocketAddress localAddress)
绑定ssh服务端的serverPort端口, 到本地主机的port端口上.
|
void |
close() |
com.jcraft.jsch.Channel |
createChannel(ChannelType channelType)
创建Channel连接
|
String |
exec(String cmd,
Charset charset)
执行Shell命令
|
String |
exec(String cmd,
Charset charset,
OutputStream errStream)
执行Shell命令(使用EXEC方式)
此方法单次发送一个命令到服务端,不读取环境变量,执行结束后自动关闭channel,不会产生阻塞。
|
String |
execByShell(String cmd,
Charset charset)
执行Shell命令
此方法单次发送一个命令到服务端,自动读取环境变量,执行结束后自动关闭channel,不会产生阻塞。
|
com.jcraft.jsch.Session |
getRaw() |
boolean |
isConnected()
是否连接状态
|
com.jcraft.jsch.Channel |
openChannel(ChannelType channelType)
打开Channel连接
|
JschSftp |
openSftp(Charset charset)
打开SFTP会话
|
com.jcraft.jsch.ChannelShell |
openShell()
打开Shell连接
|
void |
unBindLocalPort(InetSocketAddress localAddress)
解除本地端口映射
|
void |
unBindRemotePort(InetSocketAddress remoteAddress)
解除远程端口映射
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitbindLocalPort, unBindLocalPortpublic JschSession(com.jcraft.jsch.Session raw,
long timeout)
raw - Sessiontimeout - 连接超时时常,0表示不限制public boolean isConnected()
SessionisConnected in interface Sessionpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionpublic void bindLocalPort(InetSocketAddress localAddress, InetSocketAddress remoteAddress) throws SshException
SessionbindLocalPort in interface SessionlocalAddress - 本地主机和端口remoteAddress - 远程主机和端口SshExceptionpublic void unBindLocalPort(InetSocketAddress localAddress)
SessionunBindLocalPort in interface SessionlocalAddress - 需要解除的本地地址public void bindRemotePort(InetSocketAddress remoteAddress, InetSocketAddress localAddress) throws SshException
SessionbindRemotePort in interface SessionremoteAddress - ssh服务端上要被绑定的地址localAddress - 转发到的本地地址SshException - 端口绑定失败异常public void unBindRemotePort(InetSocketAddress remoteAddress)
SessionunBindRemotePort in interface SessionremoteAddress - 需要解除的远程地址和端口public com.jcraft.jsch.Channel createChannel(ChannelType channelType)
channelType - 通道类型,可以是shell或sftp等,见ChannelTypeChannelpublic com.jcraft.jsch.ChannelShell openShell()
ChannelShellpublic com.jcraft.jsch.Channel openChannel(ChannelType channelType)
channelType - 通道类型,可以是shell或sftp等,见ChannelTypeChannelpublic JschSftp openSftp(Charset charset)
charset - 编码JschSftppublic String exec(String cmd, Charset charset)
cmd - 命令charset - 发送和读取内容的编码ChannelExecpublic String exec(String cmd, Charset charset, OutputStream errStream)
此方法单次发送一个命令到服务端,不读取环境变量,执行结束后自动关闭channel,不会产生阻塞。
cmd - 命令charset - 发送和读取内容的编码errStream - 错误信息输出到的位置Copyright © 2025. All rights reserved.