我正在寻找一个简单的例子,如何在Jsch中使用Expect4j(使用Shell不可执行) 我的意思是如何发送命令(〜8)到服务器,以及如何打印输出响应。Jsch shell/Expecdt4j简单例子?
到目前为止我有这:
JSch jsch=new JSch();
String host="www.superserver.uk.com";
String user="tom1234";
String passwd="12345a";
Session session=jsch.getSession(user, host, 22);
session.setPassword(passwd);
session.setConfig("StrictHostKeyChecking", "no"); // if yes nothing works, but we're secure!
session.connect();
Channel channel=session.openChannel("shell");//only shell
channel.setInputStream(System.in);// enter lrp_list
channel.setOutputStream(System.out);
我想发送命令是这样的:命令=( “lrp_list;使用newgrp XXX;日期”);发送(命令); 也有一些例子,我发现只有时间限制的工作;而且我需要像上面的代码那样,即使超过15分钟也会超出命令。
您还必须调用shellStream.flush()。 – jmpyle771 2013-08-15 14:21:47