1
Jcraft Jsch 라이브러리를 사용하여 Java 응용 프로그램을 통해 라우터를 관리하려고합니다.JSh를 사용하여 SSH를 통해 실행되는 명령에 입력/부속 명령 제공
TFTP 서버를 통해 라우터 구성을 보내려고합니다. 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 InputStreamReader(in));
String line;
int index = 0;
StringBuilder sb = new StringBuilder();
while ((line = reader.readLine()) != null)
{
System.out.println(line);
}
session.disconnect();
는 내가 그 연속적인 명령을 실행할 수있는
라인이 잘못된 자동 명령 '192.168.50.1'
는 문제가있다 얻을 .
고마워요. 이제 작동합니다. – user6624302