[Java] 纯文本查看 复制代码public List SSH(String host,String username,String passwd,int port,String command) throws JSchException, IOException {
List list=new ArrayList();
JSch jsch = new JSch();
Session session = jsch.getSession(username, host, port);
session.setPassword(passwd);
session.setConfig("StrictHostKeyChecking", "no");
session.connect(60 * 1000);
Channel channel = session.openChannel("exec");
((ChannelExec) channel).setCommand(command);
channel.setInputStream(null);
((ChannelExec) channel).setErrStream(System.err);
InputStream in = channel.getInputStream();
channel.connect();
byte[] by = new byte[1024];
while (true) {
while (in.available() > 0) {
int i = in.read(by, 0, 1024);
if (i < 0) break;
list.add(new String(by, 0, i));
}
if (channel.isClosed()) {
if (in.available() > 0) continue;
break;
}
try {
Thread.sleep(1000);
} catch (Exception ee) {
}
}
channel.disconnect();
session.disconnect();
return list;
}
最后
以上就是活力荷花最近收集整理的关于安卓连接linux服务器地址,Android 远程连接linux的ssh怎么实现的全部内容,更多相关安卓连接linux服务器地址,Android内容请搜索靠谱客的其他文章。
发表评论 取消回复