Sending commands to server via JSch shell channel

后端 未结 9 974
渐次进展
渐次进展 2020-11-30 03:37

I can\'t figure it out how I can send commands via JSch shell channel.

I do this, but it doesn\'t work:

JSch shell = new JSch();
String command = \"c         


        
9条回答
  •  旧时难觅i
    2020-11-30 04:02

    With piped input and output streams seems interesting:

    JSch jsch = new JSch();
    jsch.addIdentity("/home/audrius/.ssh/blablabla", "blablablabla");
    
    String user = "audrius";
    String host = "ultrastudio.org";
    
    Session session = jsch.getSession(user, host, 439);
    session.setConfig("StrictHostKeyChecking", "no");           
    session.connect();
    
    Channel channel = session.openChannel("shell");
    
    PipedInputStream pip = new PipedInputStream(40);
    channel.setInputStream(pip);
    
    PipedOutputStream pop = new PipedOutputStream(pip);
    PrintStream print = new PrintStream(pop);           
    channel.setOutputStream(System.out);
    
    print.println("ls");
    

提交回复
热议问题