我已经成功地使用JSch库创建了到服务器的SSH连接,但是我不知道如何将子系统NETCONF添加到SSH连接。
手动操作时,与sybsystem NETCONF建立SSH连接的命令行为ssh -p 4444 nerconf@myserver -s netconf。
如何使用JSch将选项-s netconf添加到SSH连接?JSch是否支持NETCONF的子系统?
发布于 2018-03-21 15:42:37
JSch通常支持SSH子系统,但不实现任何NETCONF特定的东西(这不是必需的)。
您所需要做的就是进行以下调用(伪代码):
com.jcraft.jsch.JSch ssh = new com.jcraft.jsch.JSch();
com.jcraft.jsch.Session session = ssh.getSession(username, host, port);
session.setUserInfo(myUserInfo); // authentication
session.connect(connectTimeout);
// this opens up the proper subsystem for NETCONF
com.jcraft.jsch.ChannelSubsystem subsystem = (com.jcraft.jsch.ChannelSubsystem) session.openChannel("subsystem");
subsystem.setSubsystem("netconf");
// at this point you may get your streams
subsystem.getInputStream();
subsystem.getErrStream();
subsystem.getOutputStream();
subsystem.connect();对于NETCONF,子系统必须满足的唯一要求是正确的子系统名称。
发布于 2021-03-18 14:59:05
谢谢,普雷迪。
这是我的工作。netconf-hello已完成。
session = new JSch().getSession("username", "remote-ip", netconf-port);
session.setPassword("your-password");
session.setConfig("StrictHostKeyChecking", "no");
session.connect();
channel = (ChannelSubsystem) session.openChannel("subsystem"); //necessary
channel.setSubsystem("netconf"); //necessary
channel.connect();
System.out.println(channel.isConnected()); // debug use
System.out.println(session.isConnected()); // debug use
InputStream inputStream = channel.getInputStream(); // use this to read
OutputStream outputStream = channel.getOutputStream();
PrintStream printStream = new PrintStream(outputStream); // use this to sendhttps://stackoverflow.com/questions/49397575
复制相似问题