小编use*_*302的帖子

为使用 JSch 通过 SSH 执行的命令提供输入/子命令

我正在尝试使用 Jcraft Jsch 库通过 Java 应用程序管理路由器。

我正在尝试通过 TFTP 服务器发送路由器配置。问题出在我的 Java 代码中,因为它适用于 PuTTY。

这是我的Java代码:

int port=22;
String name ="R1";
String ip ="192.168.18.100";
String password ="root";

JSch jsch = new JSch();
Session session = jsch.getSession(name, ip, port);
session.setPassword(password);
session.setConfig("StrictHostKeyChecking", "no");
System.out.println("Establishing Connection...");
session.connect();
System.out.println("Connection established.");

ChannelExec channelExec = (ChannelExec)session.openChannel("exec");

InputStream in = channelExec.getInputStream();
channelExec.setCommand("enable");

channelExec.setCommand("copy run tftp : ");
//Setting the ip of TFTP server 
channelExec.setCommand("192.168.50.1 : ");
// Setting the name of file
channelExec.setCommand("Config.txt ");

channelExec.connect();

BufferedReader reader = new BufferedReader(new …
Run Code Online (Sandbox Code Playgroud)

java ssh router cisco jsch

2
推荐指数
1
解决办法
2533
查看次数

标签 统计

cisco ×1

java ×1

jsch ×1

router ×1

ssh ×1