ssh to debian, then telnet to other devices

Sep 4, 2012 at 9:06 PM


I'm writing application for my personal purposes in which I need to connect to Debian ssh server, and then, from this server, telnet to various devices and execute some commands on them and read the answer.

I have successfully connected to ssh server using your library and I'm sending "telnet deviceHostName" command to it (using RunCommand()), unfortunatelly I have problem with entering username and password, because after this command my application freezes for about minute and after that I get response with welcome message and prompt for username.

I tried to run command as "telnet deviceHostName\r\nLogin\r\nPassword\r\n\r\n", but it didnt help.

Could you please advise me how should I continue?

Thank you :)

Sep 9, 2012 at 1:54 AM


How are you initializing SshClient?

Jan 24, 2014 at 5:32 PM
hi im elhave and im newbie in coding

need help. i have same issue
  1. i want to connect to ssh server first.
  2. from that ssh server i want to telnet to other server/cisco router
i have succesfully got into ssh server.
but the telnet command, and any other command that return as question from the ssh server or ask back an input from me just don't work.

here's how i write the code

class Program
    static void Main(string[] args)
        string userName = "elhave";
        string serverName = "";//mysshserver
        string password = "mypass";

        var keyboardAuthMethod = new KeyboardInteractiveAuthenticationMethod(userName);
        keyboardAuthMethod.AuthenticationPrompt += delegate(Object senderObject, AuthenticationPromptEventArgs eventArgs) {
            foreach (var prompt in eventArgs.Prompts){
                        if (prompt.Request.Equals("Password: ", StringComparison.InvariantCultureIgnoreCase)) {
                            prompt.Response = password;

        var passwordAuthMethod = new PasswordAuthenticationMethod(userName, password);
        var connectInfo = new ConnectionInfo(serverName, userName, passwordAuthMethod, keyboardAuthMethod);

        string hasil = "";
        using (var serverConnection = new SshClient(connectInfo))
            var command = serverConnection.RunCommand("who");//inisialization
            while (true)
                nextcommand = Console.ReadLine();
                command = serverConnection.RunCommand(nextcommand);
                if (nextcommand == "break") {



i expect the app to work like putty. read command, run command, and display the result. but seems like i cant perform it with this code.
here i type man command that will return question from server.
on putty it worked but on my application it did work.