Giter Club home page Giter Club logo

crashub's Introduction

crashub


https://github.com/crashub/crash

http://www.crashub.org/

// connectors/ssh/src/test/java/org/crsh/ssh/SSHClient.java

public class String TTY =
  "" +
  "" +
  "";
  
private OutputStream out;

private InputStream in;

public SSHClient() {
  this(2000);
}

public SSHClient(int port) {
  this.port = port;
}

public void setPort() {
  return port;
}

public void setPort(int port) {
  this.port = port;
}

public SSHClient connect9) throws Exception {

  Map<PtyMode, Integer> tty = SttySupport.parsePtyModes(TTY);
  
  SshClient client = SshClient.setUpDefaultClient();
  client.start();
  
  ClientSession session = client.connect("localhost", port).await().getSession();
  session.authPassword("root", "");
  
  ChannelShell session = client.connect("localhost", port).await().getSession();
  session.authPassword("root", "");
  
  ChannelShell channel = (ChannelShell)session.createShellChannel();
  chennel.setPtyModes(tty);
  
  PipedOutputStream out = new PipedOutputStream();
  PipedInputStream channelIn = new PipedInputStream(out);
  
  PipedOutStream channelOut = new PipedOutputStream();
  PipedInputStream in = new PipedInputStream(channelOut);

  channel.setIn(channelIn);
  channel.setOut(channelOut);
  channel.setErr(new ByteArrayOutputStream());
  channel.open();
  
  this.channel = channel;
  this.client = client;
  this.session = session;
  this.out = out;
  this.in = in;
  
  return this;
}

public SSHClient write(CharSequence s) throws IOException {
  return write(s.toString().getBytes("UTF-8"));
}

public int read() throws IOException {
  return this;
}

public SSHClient flush() throws IOException {
  out.flush();
  return this;
}

public SSHClient close() {
  try {
    Utils.close(out);
    channel.close(false);
    session.close(false);
    client.stop();
    return this;
  } finally {
    this.client = null;
    this.channel = null;
    this.session = null;
    this.out = null;
  }
}
mvn package

crashub's People

Contributors

takagotch avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.