当前位置: 首页>>代码示例>>Java>>正文


Java SessionChannelClient.close方法代码示例

本文整理汇总了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;
}
 
开发者ID:qmetry,项目名称:qaf,代码行数:29,代码来源:SshUtil.java

示例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);
    }
}
 
开发者ID:swift-lang,项目名称:swift-k,代码行数:15,代码来源:Exec.java

示例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;
}
 
开发者ID:qmetry,项目名称:qaf,代码行数:58,代码来源:SshUtil.java


注:本文中的com.sshtools.j2ssh.session.SessionChannelClient.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。