Using Renci SSH.NET with Expect.NET?

Aug 1, 2014 at 8:14 PM

I stumbled onto Expect.NET (NuGet here), and before I go crazy looking, have any of you used is with SSH.NET?

I'm new to it, so I don't see how to 'attach' Expect to an SSH.NET session yet.

For those unaware, a test ping program I modified from the examples Expect comes with looks like this:
Imports ExpectNet

Module Module1

    Sub Main()
        Dim s As Session = Expect.Spawn(New ProcessSpawnable("cmd.exe"))
            s.Expect(">", Sub(x) Console.WriteLine("Prompt --> " + x))
            s.Timeout = 1000
            s.Send("dir c:\" + Environment.NewLine)
            s.Expect("Program Files", Sub(x) Console.WriteLine(x))
            s.Expect(">", Sub() s.Send("ping" + Environment.NewLine))
        Catch ex As System.TimeoutException
        End Try
        s.Timeout = 500
            s.Expect("Lost = 0", Sub() s.Send("ping" + Environment.NewLine))
            s.Expect("Lost = 0", Sub(x) Console.WriteLine(x))
        Catch ex As System.TimeoutException
            Console.WriteLine("Timeout({0})", s.Timeout)
            s.Timeout += 500
            GoTo TRY_AGAIN
        Catch ex As Exception
            Console.WriteLine("Exception " & ex.ToString)
        End Try
    End Sub
End Module
Already it is looking like a fantastic way for me to deal with Cisco products. There should be a way to simply point Expect to the ssh session, and let it 'talk' over ssh once SSH.NET has connected, right?

Any pointers appreciated!


P.S. Why I am I asking? Because I know that Expect will call an SSH executable. I am trying not to create vulnerabilities by calling 3rd party programs. Keeping everything ssh inside the app(s) is the best way-providing I can figure it out with your help! :)