SSH.NET icon indicating copy to clipboard operation
SSH.NET copied to clipboard

executing telnet command , result empty

Open rakeshkhoodeeram opened this issue 9 years ago • 3 comments

hello, I can connect to server with

var connectionInfo = new KeyboardInteractiveConnectionInfo(ip, 22, username);
                connectionInfo.AuthenticationPrompt += delegate (object sender, AuthenticationPromptEventArgs e)
                {
                    foreach (var prompt in e.Prompts)
                    {
                        if (prompt.Request.Equals("Password: ", StringComparison.InvariantCultureIgnoreCase))
                        {
                            prompt.Response = "password";
                        }
                    }
                };

but when i try executing telnet command, I do not seem to succeed. (maybe i should run async or wait)

var sshclient = new SshClient(connectionInfo)
 var terminal = sshclient.RunCommand("telnet xxx.xxx.xxx.xx 9819" + Environment.NewLine);
                            log.Info("Command>" + terminal.CommandText);
                            log.Info("Result>" + terminal.Result);

after telnet, i execute other commands and all of them fails (error: unknown command, i presume the telnet command failed, so the following ones also fail)

rakeshkhoodeeram avatar Apr 13 '17 16:04 rakeshkhoodeeram

If you run something basic like 'ls' does it still report unknown command? Just wondering if it's actually telnet that's giving the error, not ssh.

keyoti avatar Apr 19 '17 17:04 keyoti

@rakeshkhoodeeram could you please provide more details and answer to @keyoti question?

kasbst avatar Apr 27 '17 12:04 kasbst

This is because you are using RunCommand when you establish a connection you do not start a shell on the host, for that after connection you will need to create a stream from the connection, this will create a terminal that you can issue and read from. RunCommand will simply do an exec on the system and close the process so it calls the telnet command and closes it and then you are sending other commands thinking that the connection retains a state.

On Apr 13, 2017, at 12:40 PM, rakeshkhoodeeram [email protected] wrote:

hello, I can connect to server with var connectionInfo = new KeyboardInteractiveConnectionInfo(ip, 22, username); connectionInfo.AuthenticationPrompt += delegate (object sender, AuthenticationPromptEventArgs e) { foreach (var prompt in e.Prompts) { if (prompt.Request.Equals("Password: ", StringComparison.InvariantCultureIgnoreCase)) { prompt.Response = "password"; } } }; but when i try executing telnet command, I do not seem to succeed. (maybe i should run async or wait) var sshclient = new SshClient(connectionInfo) var terminal = sshclient.RunCommand("telnet xxx.xxx.xxx.xx 9819" + Environment.NewLine); log.Info("Command>" + terminal.CommandText); log.Info("Result>" + terminal.Result);

after telnet, i execute other commands and all of them fails (error: unknown command, i presume the telnet command failed, so the following ones also fail)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/sshnet/SSH.NET/issues/205, or mute the thread https://github.com/notifications/unsubscribe-auth/AAf0HppkdLbMidowdZCQLB3jDw69HAg0ks5rvk_5gaJpZM4M8754.

darkoperator avatar Apr 27 '17 12:04 darkoperator