Java远程执行Linux命令
来源:互联网 发布:c 并发编程实战 pdf 编辑:程序博客网 时间:2024/06/06 18:34
//指明连接主机的IP地址
Connection conn = new Connection(hostname);
Session ssh = null;
try {
//连接到主机
conn.connect();
//使用用户名和密码校验
boolean isconn = conn.authenticateWithPassword(username, password);
if(!isconn){
System.out.println("用户名称或者是密码不正确");
}else{
System.out.println("已经连接OK");
ssh = conn.openSession();
ssh.execCommand(command);
InputStream is = new StreamGobbler(ssh.getStdout());
BufferedReader brs = new BufferedReader(new InputStreamReader(is));
while(true){
String line = brs.readLine();
if(line==null){
break;
}
System.out.println(line);
}
}
//连接的Session和Connection对象都需要关闭
ssh.close();
conn.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Connection conn = new Connection(hostname);
Session ssh = null;
try {
//连接到主机
conn.connect();
//使用用户名和密码校验
boolean isconn = conn.authenticateWithPassword(username, password);
if(!isconn){
System.out.println("用户名称或者是密码不正确");
}else{
System.out.println("已经连接OK");
ssh = conn.openSession();
ssh.execCommand(command);
InputStream is = new StreamGobbler(ssh.getStdout());
BufferedReader brs = new BufferedReader(new InputStreamReader(is));
while(true){
String line = brs.readLine();
if(line==null){
break;
}
System.out.println(line);
}
}
//连接的Session和Connection对象都需要关闭
ssh.close();
conn.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
0 0
- java远程执行linux命令
- java远程执行linux命令
- java远程执行linux命令
- Java远程执行Linux命令
- java 远程执行linux命令
- Java程序执行远程linux命令
- Java 远程执行 Linux 的命令
- java远程调用ssh2执行Linux命令
- linux 执行远程命令
- Java远程连接Linux系统并执行Linux命令
- Windwos远程执行Linux命令
- linux 远程命令执行不
- linux shell 远程执行命令
- linux 远程登录执行命令
- Python远程执行Linux命令
- Linux shell 远程执行命令
- java应用程序远程登录linux并执行其命令
- java 使用jsch 远程链接linux执行命令
- Asp.net MVC4 + signalR 聊天室实现
- 判断机器大小端
- Opencv的配置
- ggsci命令提示符中看不到的OGG进程
- xcorr 自相关 c++实现
- Java远程执行Linux命令
- 同时安装VS2010 + Qt4.8.6 + Qt Add-in 和VS2008 + Qt4.8.6 + Qt Add-in
- 使用maven构建android项目
- python 入门
- 【Hadoop】1、Hadoop开山篇之虚拟机下ubuntu安装jdk1.7
- structs2基本程序创建
- logcat命令行输出tag为Mylistview,日志级别为info,以及多个tag的写法
- 面向对象杂想:
- arduino五天小结