Hi, I am really banging my head on this problem. I would like to make app for automation of many network devices in our network. I decided for Chilkat SSH. We must connect to our network devices through JUMP linux server. Please Help - In my trying I was able to reach cisco device once but I dont know how. Also I would like to have the output of the command. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 {
|
Thanks! I would first try using a bare-LF line-ending, because that's normal for a Linux type system. (If the SSH server is on a Windows system, then you might need "\r\n"). So just do "ena\n". You would never do "\n\r", but only sometimes "\r\n". On a Linux system, the "\r" in the "\r\n" might be considered a char in the command and you might get some sort of "unrecognized command" error. (If you've ever saved a .sh shell script on Windows with "\r\n" line-endings and the copied to a Linux box and tried to run it, you'll know what I mean..) |
What version of .NET are you using? I'll send you a pre-release of v9.5.0.66 to test. In any case, there is one misconception in the above code. You're thinking that GetReceivedText is reading from the SSH server. It's not. You should instead call one of the ChannelRead or ChannelReceive methods to read from the channel. If successful, the received data is then "picked up" by calling GetReceivedText. Also, sometimes the line-endings used in the command make a difference. If a bare-LF line ending doesn't trigger the execution of the command, then try CRLF ("\r\n"). This behavior is server dependent. Hi, I am using 9.5.0.65 btw I changed last part from GetReceivedText to ChannelRead but still no data
(Mar 14 '17 at 17:08)
marhyno
|
Make sure to read the documentation more closely... ChannelRead returns an integer value, NOT a string. Like I just said, you first ChannelRead/ChannelReceive, then if successful, get what was received via GetReceivedText.. OK thanks, I checked the documentation and tried a few tests. isConnected = true ChannelIsopen = true
This returns -1 which means somewhere is a problem
So naturally this returns nothing
(Mar 14 '17 at 17:31)
marhyno
|
UPDATE - error message provided
--ChannelRead --ChilkatLog |
Also, after opening the channel, you need to start a shell session. This optionally (usually) involves calling SendReqPty with "dumb" as the value for the terminal type, and then call SendReqShell to start a shell on the channel. Then you can send commands to the shell. The "Out of context message type 94" means you were trying to send CHANNEL_DATA, which is SSH message type 94 (i.e your command) before there was a shell session. I LOVE YOU ! it works I finally connected to the Cisco Device and prompt appeared. One last thing is - I see the prompt but ChannelSendString is not sending command
(Mar 14 '17 at 18:27)
marhyno
|
YEEEEEEEEES !!! I really love you :D, Finally after few days I am able to connect to Jump server (Debian) and then to Cisco Router and do what I want to do. This command works & sends commands to Cisco IOS ssh2.ChannelSendString(channelNum, "ena\rcisco\rshow version\r", "ansi"); Btw, Last thing I needed to change is ssh2.ChannelRead. This was not functioning (maybe it requires time-out between single commands). So I changed that to ChannelReadAndPoll and it works like charm: var cmdOutput = ssh2.ChannelReadAndPoll(channelNum, 200); |