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


Java SessionChannelClient.getOutputStream方法代码示例

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


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

示例1: setSessionChannel

import com.sshtools.j2ssh.session.SessionChannelClient; //导入方法依赖的package包/类
/**
 *
 *
 * @param session
 */
public void setSessionChannel(SessionChannelClient session) {
    this.session = session;
    this.in = session.getInputStream();
    this.out = session.getOutputStream();
    session.setName(name);
}
 
开发者ID:UniversityofWarwick,项目名称:j2ssh-fork,代码行数:12,代码来源:SubsystemClient.java

示例2: main

import com.sshtools.j2ssh.session.SessionChannelClient; //导入方法依赖的package包/类
/**
 * The main program for the PasswordConnect class
 *
 * @param args The command line arguments
 */
public static void main(String args[]) {
  try {
    // Setup a logfile
    /*Handler fh = new FileHandler("example.log");
    fh.setFormatter(new SimpleFormatter());
    Logger.getLogger("com.sshtools").setUseParentHandlers(false);
    Logger.getLogger("com.sshtools").addHandler(fh);
    Logger.getLogger("com.sshtools").setLevel(Level.ALL);*/
    // Configure J2SSH (This will attempt to install the bouncycastle provider
    // under jdk 1.3.1)
    ConfigurationLoader.initialize(false);
    System.out.print("Connect to host? ");
    System.out.print("Connect to host? ");
    String hostname = reader.readLine();
    // Make a client connection
    SshClient ssh = new SshClient();
    SshConnectionProperties properties = new SshConnectionProperties();
    properties.setHost(hostname);
    // Connect to the host
    ssh.connect(properties);
    // Create a password authentication instance
    KBIAuthenticationClient kbi = new KBIAuthenticationClient();
    // Get the users name
    System.out.print("Username? ");
    // Read the password
    String username = reader.readLine();
    kbi.setUsername(username);
    kbi.setKBIRequestHandler(new KBIRequestHandler() {
      public void showPrompts(String name, String instructions,
                              KBIPrompt[] prompts) {
        System.out.println(name);
        System.out.println(instructions);
        String response;
        if (prompts != null) {
          for (int i = 0; i < prompts.length; i++) {
            System.out.print(prompts[i].getPrompt() + ": ");
            try {
              response = reader.readLine();
              prompts[i].setResponse(response);
            }
            catch (IOException ex) {
              prompts[i].setResponse("");
              ex.printStackTrace();
            }
          }
        }
      }
    });
    // Try the authentication
    int result = ssh.authenticate(kbi);
    // Evaluate the result
    if (result == AuthenticationProtocolState.COMPLETE) {
      // The connection is authenticated we can now do some real work!
      SessionChannelClient session = ssh.openSessionChannel();
      if(!session.requestPseudoTerminal("vt100", 80, 24, 0, 0, ""))
        System.out.println("Failed to allocate a pseudo terminal");
      if(session.startShell()) {
        IOStreamConnector input =
            new IOStreamConnector(System.in, session.getOutputStream());
        IOStreamConnector output =
            new IOStreamConnector(session.getInputStream(), System.out);
        output.getState().waitForState(IOStreamConnectorState.CLOSED);
      }else
        System.out.println("Failed to start the users shell");
      ssh.disconnect();
    }
  }
  catch (Exception e) {
    e.printStackTrace();
  }
}
 
开发者ID:UniversityofWarwick,项目名称:j2ssh-fork,代码行数:77,代码来源:KBIConnect.java


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