Skip to content
Advertisement

Providing input/subcommands to command executed over SSH with JSch

I’m trying to manage router via Java application using Jcraft Jsch library.

I’m trying to send Router Config via TFTP server. The problem is in my Java code because this works with PuTTY.

This my Java code:

JavaScript

I get

Line has an invalid autocommand ‘192.168.50.1’

The problem is how can I run those successive commands.

Advertisement

Answer

Calling ChannelExec.setCommand multiple times has no effect.

And even if it had, I’d guess that the 192.168.50.1 : and Config.txt are not commands, but inputs to the copy run tftp : command, aren’t they?

If that’s the case, you need to write them to the command input.

Something like this:

JavaScript

In general, it’s always better to check if the command has better “API” than feeding the commands to input. Commands usually have command-line arguments/switches that serve the desired purpose better.


A related question: Provide inputs to individual prompts separately with JSch.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement