multiple commands

Feb 24, 2012 at 8:39 PM
Edited Feb 24, 2012 at 8:41 PM

hi,

 

i have this dll working fine for single commands like "show clock" on my switch.

however if i try to run the code below it hangs with no error returned

 any help is appreciated

thanks

damo642

private void button2_Click(object sender, EventArgs e)
        {
            try
            {

                using (var client = new SshClient("192.168.1.31", "admin", "admin"))
               {
                client.Connect();
                var cmd = client.CreateCommand("enable");
                var result = cmd.Execute();
                Txt_Entry.Text = Txt_Entry.Text + result;
                cmd = client.CreateCommand("admin");
                result = cmd.Execute();
                Txt_Entry.Text = Txt_Entry.Text + result;
                cmd = client.CreateCommand("show running-config");
                result = cmd.Execute();
                Txt_Entry.Text = Txt_Entry.Text + result;
                client.Disconnect();
              }
            }


            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
       


            }

 


Feb 24, 2012 at 8:41 PM

i forgot to mention it is on the

var cmd = client.CreateCommand("enable");

var result = cmd.Execute();

line that the problem is -

Feb 25, 2012 at 3:17 PM
Edited Feb 25, 2012 at 3:22 PM

so the problem definitely is that the enable command requires a password to be entered (its a cisco switch) - its just sitting there and timesout

- i need to enter the password but cant as the software is waiting for a resposnse i think

anyone know how to do this? (interactive mode i believe)

thanks

Feb 25, 2012 at 6:04 PM

hello guys,

 

i got around the problem by setting the default privileges of my user to 15 - hence enable is not required

id still like to understand how to pass paramaters like enable that then require input (i.e my password)

command below for cisco

Username theuser privilege 15 password thepassword

Feb 27, 2012 at 8:06 AM
Edited Feb 27, 2012 at 8:07 AM

HI Damo,

Since you seem to require an interactive session after the inital SSH connection, you might need to create and use a Shell on the session, rather than executing commands directly...

I use shell on interactive sessions and it works well...

There is a thread here about shell usage with examples etc

http://sshnet.codeplex.com/discussions/301739

 

 

cheers,

 

Paul.