概述
try{
BufferedWriter out= null;
boolean result = false;
Session session = null;
Connection conn = null;
ConnectionInfo info = null;
System.out.println("connection 122 start...");
conn = new Connection("192.168.2.122", 22);
info = conn.connect();
result = conn.authenticateWithPassword("h, "ad");
session = conn.openSession();
session.requestPTY("bash");
session.startShell();
StringBuffer jtais = new StringBuffer();
StringBuffer jtaerror = new StringBuffer();
ReadThread is = new ReadThread(session.getStdout(), new PrintStream(System.out), jtais);
ReadThread error = new ReadThread(session.getStderr(), new PrintStream(System.out), jtaerror);
is.start();
error.start();
out = new BufferedWriter(new OutputStreamWriter(session.getStdin(), "utf-8"));
out.write("sudo su qwe");out.flush();
out.write("n");out.flush();
out.write("adminhanzqn");out.flush();
for(int i = 0; i < 10; i++){
if(jtais.indexOf("password") > -1){
break;
}
Thread.sleep(1000);
}
out.write("adn");out.flush();
out.write("cd /home//n");out.flush();
System.out.println("update over ...");
out.write("clearn");out.flush();
session.close();
System.exit(-1);
}catch(Exception e){
e.printStackTrace();
}
最后
以上就是腼腆咖啡豆为你收集整理的java ssh 客户端的全部内容,希望文章能够帮你解决java ssh 客户端所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复