本文整理汇总了Java中com.sshtools.j2ssh.session.SessionChannelClient.close方法的典型用法代码示例。如果您正苦于以下问题:Java SessionChannelClient.close方法的具体用法?Java SessionChannelClient.close怎么用?Java SessionChannelClient.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sshtools.j2ssh.session.SessionChannelClient
的用法示例。
在下文中一共展示了SessionChannelClient.close方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeCommand
import com.sshtools.j2ssh.session.SessionChannelClient; //导入方法依赖的package包/类
public static String executeCommand(String command) throws Exception {
SessionChannelClient session = null;
String res = "";
try {
SshClient ssh = connectSsh();
// String command = getBundle().getString("ssh.cmd");
session = ssh.openSessionChannel();
OutputStream out = new java.io.ByteArrayOutputStream();
session = ssh.openSessionChannel();
IOStreamConnector output = new IOStreamConnector();
output.connect(session.getInputStream(), out);
if (session.executeCommand(command)) {
session.getState().waitForState(ChannelState.CHANNEL_CLOSED, 15000);
res = out.toString();
} else {
res = "Unable to execute command " + command;
}
} finally {
try {
session.close();
} catch (Exception e) {
}
}
return res;
}
示例2: execute
import com.sshtools.j2ssh.session.SessionChannelClient; //导入方法依赖的package包/类
public void execute(SessionChannelClient session)
throws IllegalSpecException, InvalidSecurityContextException,
InvalidServiceContactException, TaskSubmissionException,
JobException {
try {
executeCommand(session);
session.close();
}
catch (IOException sshe) {
logger.error(sshe);
throw new TaskSubmissionException("SSH Connection failed: "
+ sshe.getMessage(), sshe);
}
}
示例3: executeSudoCommand
import com.sshtools.j2ssh.session.SessionChannelClient; //导入方法依赖的package包/类
/**
* Get shell and execute command.
*
* @param cmd
* @return
* @throws Exception
*/
public String executeSudoCommand(String command) throws Exception {
String res = "";
SessionChannelClient session = null;
try {
SshClient ssh = connectSsh();
session = ssh.openSessionChannel();
if (session.requestPseudoTerminal("isfw", 80, 24, 0, 0, "")) {
if (session.startShell()) {
session.getOutputStream().write((command + "\n").getBytes());
InputStream in = session.getInputStream();
byte buffer[] = new byte[255];
int read;
while ((read = in.read(buffer)) > 0) {
res += new String(buffer, 0, read);
System.out.println("res: " + res);
if (res.contains("password")) {
session.getOutputStream().write((getBundle().getString("ssh.pwd") + "\n").getBytes());
res = command + "\n";
}
if (res.contains(command)) {
if (res.endsWith("]$ ")) {
break;
}
if (command.equalsIgnoreCase("status") && res.endsWith("]$ ")) {
break;
}
}
}
} else {
res = "Unable to start shell.";
}
} else {
res = "Unable to request terminal.";
}
} finally {
try {
session.close();
} catch (Exception e) {
}
}
return res;
}