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


Java ChannelShell.connect方法代码示例

本文整理汇总了Java中com.jcraft.jsch.ChannelShell.connect方法的典型用法代码示例。如果您正苦于以下问题:Java ChannelShell.connect方法的具体用法?Java ChannelShell.connect怎么用?Java ChannelShell.connect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.jcraft.jsch.ChannelShell的用法示例。


在下文中一共展示了ChannelShell.connect方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testTestCommand

import com.jcraft.jsch.ChannelShell; //导入方法依赖的package包/类
@Test
public void testTestCommand() throws JSchException, IOException {
    JSch jsch = new JSch();
    Session session = jsch.getSession("admin", "localhost", properties.getShell().getPort());
    jsch.addIdentity("src/test/resources/id_rsa");
    Properties config = new Properties();
    config.put("StrictHostKeyChecking", "no");
    session.setConfig(config);
    session.connect();
    ChannelShell channel = (ChannelShell) session.openChannel("shell");
    PipedInputStream pis = new PipedInputStream();
    PipedOutputStream pos = new PipedOutputStream();
    channel.setInputStream(new PipedInputStream(pos));
    channel.setOutputStream(new PipedOutputStream(pis));
    channel.connect();
    pos.write("test run bob\r".getBytes(StandardCharsets.UTF_8));
    pos.flush();
    verifyResponse(pis, "test run bob");
    pis.close();
    pos.close();
    channel.disconnect();
    session.disconnect();
}
 
开发者ID:anand1st,项目名称:sshd-shell-spring-boot,代码行数:24,代码来源:SshdShellAutoConfigurationWithPublicKeyAndBannerImageTest.java

示例2: testResizeHandler

import com.jcraft.jsch.ChannelShell; //导入方法依赖的package包/类
@Test
public void testResizeHandler(TestContext context) throws Exception {
  Async async = context.async();
  termHandler = term -> {
    term.resizehandler(v -> {
      context.assertEquals(20, term.width());
      context.assertEquals(10, term.height());
      async.complete();
    });
  };
  startShell();
  Session session = createSession("paulo", "secret", false);
  session.connect();
  ChannelShell channel = (ChannelShell) session.openChannel("shell");
  channel.connect();
  OutputStream out = channel.getOutputStream();
  channel.setPtySize(20, 10, 20 * 8, 10 * 8);
  out.flush();
  channel.disconnect();
  session.disconnect();
}
 
开发者ID:vert-x3,项目名称:vertx-shell,代码行数:22,代码来源:SSHServerTest.java

示例3: connect

import com.jcraft.jsch.ChannelShell; //导入方法依赖的package包/类
public void connect(Connection connection, TerminalPanel remoteTerminalPanel) throws JSchException, IOException {
    String newKey = connection.getUser() + connection.getRemoteHost();
    if (newKey.equals(key)) {
        return;
    }
    key = newKey;

    disconnect();

    JSch jsch = new JSch();
    session = jsch.getSession(connection.getUser(), connection.getRemoteHost(), 22);
    session.setPassword(connection.getPassword());
    session.setConfig("StrictHostKeyChecking", "no");
    session.connect(5000);

    ChannelShell channel = (ChannelShell) session.openChannel("shell");
    channel.setPtyType("vt102");

    OutputStream inputToChannel = channel.getOutputStream();
    PrintStream printStream = new PrintStream(inputToChannel, true);
    remoteTerminalPanel.setPrintStream(printStream);

    InputStream outFromChannel = channel.getInputStream();

    Runnable run = new TerminalWatcher(outFromChannel, remoteTerminalPanel.getTextArea());
    thread = new Thread(run);
    thread.start();

    channel.connect();
}
 
开发者ID:malafeev,项目名称:JFTClient,代码行数:31,代码来源:RemoteTerminal.java

示例4: getExpect

import com.jcraft.jsch.ChannelShell; //导入方法依赖的package包/类
private Expect4j getExpect() {
    try {
        log.debug(String.format("Start logging to %[email protected]%s:%s",user,ip,port));
        JSch jsch = new JSch();
        session = jsch.getSession(user, ip, port);
        session.setPassword(password);
        Hashtable<String, String> config = new Hashtable<String, String>();
        config.put("StrictHostKeyChecking", "no");
        session.setConfig(config);
        localUserInfo ui = new localUserInfo();
        session.setUserInfo(ui);
        session.connect();
        channel = (ChannelShell) session.openChannel("shell");
        Expect4j expect = new Expect4j(channel.getInputStream(), channel
                .getOutputStream());
        channel.connect();
        log.debug(String.format("Logging to %[email protected]%s:%s successfully!",user,ip,port));
        return expect;
    } catch (Exception ex) {
        log.error("Connect to "+ip+":"+port+"failed,please check your username and password!");
        ex.printStackTrace();
    }
    return null;
}
 
开发者ID:dipoo,项目名称:arong,代码行数:25,代码来源:Shell.java

示例5: startLoginShellSession

import com.jcraft.jsch.ChannelShell; //导入方法依赖的package包/类
public static ChannelStreams startLoginShellSession(final ExecutionEnvironment env) throws IOException, JSchException, InterruptedException {
    JSchWorker<ChannelStreams> worker = new JSchWorker<ChannelStreams>() {

        @Override
        public ChannelStreams call() throws InterruptedException, JSchException, IOException {
            ChannelShell shell = (ChannelShell) ConnectionManagerAccessor.getDefault().openAndAcquireChannel(env, "shell", true); // NOI18N

            if (shell == null) {
                throw new IOException("Cannot open shell channel on " + env); // NOI18N
            }

            shell.setPty(false);
            InputStream is = shell.getInputStream();
            InputStream es = new ByteArrayInputStream(new byte[0]);
            OutputStream os = shell.getOutputStream();
            Authentication auth = Authentication.getFor(env);
            shell.connect(auth.getTimeout() * 1000);
            return new ChannelStreams(shell, is, es, os);
        }

        @Override
        public String toString() {
            return "shell session for " + env.getDisplayName(); // NOI18N
        }
    };

    return start(worker, env, 2);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:29,代码来源:JschSupport.java

示例6: ScpClient

import com.jcraft.jsch.ChannelShell; //导入方法依赖的package包/类
public ScpClient(String host,String user,String password,boolean su,Notify notify) throws Exception{
	this.hosts = host;
	this.user = user;
	session = connect(host, user, password);
	exec = (ChannelShell) session.openChannel("shell");
	exec.setPtySize(160, 50, 1280, 800);
	input = exec.getInputStream();
	output = exec.getOutputStream();
	exec.connect();
	this.notify = notify;
	get();
	if(su){
		getSU(password);
	}
}
 
开发者ID:yanfanvip,项目名称:RedisClusterManager,代码行数:16,代码来源:ScpClient.java

示例7: ShellClient

import com.jcraft.jsch.ChannelShell; //导入方法依赖的package包/类
public ShellClient(String host, String user, String password, Notify notify) throws Exception{
	this.hosts = host;
	this.user = user;
	this.password = password;
	session = this.connect();
	shell = (ChannelShell) session.openChannel("shell");
	shell.setPtySize(160, 50, 1280, 800);
	input = shell.getInputStream();
	output = shell.getOutputStream();
	shell.connect();
	this.notify = notify;
	get(30);
}
 
开发者ID:yanfanvip,项目名称:RedisClusterManager,代码行数:14,代码来源:ShellClient.java

示例8: getShell

import com.jcraft.jsch.ChannelShell; //导入方法依赖的package包/类
public ChannelShell getShell() throws JSchException {
	ChannelShell shell = (ChannelShell) session.openChannel("shell");
	shell.setInputStream(System.in);
	shell.setOutputStream(System.out);
	shell.connect();
	return shell;
}
 
开发者ID:int32bit,项目名称:openstack-java-sdk,代码行数:8,代码来源:RemoteExecutor.java


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