cisco devices - WeOnlyDo Discussion board

cisco devices (General questions)

by epoelke, Thursday, February 03, 2005, 02:20 (7232 days ago)

Has anyone written any code to pull cisco configs? I have attempted to and it seems the data received event never fires. I am new to programming and any help would be appreciated. here is the code --

Module Module1
Dim WithEvents ssh As New WeOnlyDo.Client.SSH
Sub Main()
ssh.Hostname = 1.1.1.1
ssh.Login = user
ssh.Password = password
ssh.Encryption = WeOnlyDo.Client.SSH.EncryptionMethods.Auto
ssh.Protocol = WeOnlyDo.Client.SSH.SupportedProtocols.SSHAuto
ssh.Blocking = True
ssh.Command = ( sh run & vbCrLf)
ssh.Connect()

End Sub
Private Sub ssh_ConnectedEvent(ByVal Sender As Object, ByVal Args As WeOnlyDo.Client.SSH.ConnectedArgs) Handles ssh.ConnectedEvent
MsgBox( connected , MsgBoxStyle.Information, test )
End Sub

Private Sub ssh_DataReceivedEvent(ByVal Sender As Object, ByVal Args As WeOnlyDo.Client.SSH.DataReceivedArgs) Handles ssh.DataReceivedEvent
Dim st As String
Dim fs As New FileStream( c:config.txt , FileMode.Create)
Dim s As New StreamWriter(fs)
st = ssh.Receive
s.Write(st)
End Sub
End Module

Re: cisco devices

by wodSupport, Thursday, February 03, 2005, 10:02 (7232 days ago) @ epoelke

Eric,

I can suggest to try two things

1. Try not to set Command property, so shell is spawned instead of your command
2. Try to end commands with VbLf instead of VbCrLf

let me know if that helps.

Re: cisco devices

by epoelke, Thursday, February 03, 2005, 21:18 (7232 days ago) @ wodSupport

Nope that didnt seem to help. even with ssh.command in there on the basic VB sample it works. It just seems the data recieved event never fires from a console application for some reason.

Re: cisco devices

by wodSupport, Thursday, February 03, 2005, 22:01 (7232 days ago) @ epoelke

Any chance we could connect there and try?

BTW do you have the most recent version of the product? I believe there were some issues on SSH1 protocol which I think cisco uses.

Re: cisco devices

by epoelke, Thursday, February 03, 2005, 23:01 (7232 days ago) @ wodSupport

thanks, but i got it worked out from another post. Here is the code thats works --

Module Module1
Dim WithEvents ssh As New WeOnlyDo.Client.SSH
Dim fs As New FileStream( c:config.txt , FileMode.Append, FileAccess.Write)
Dim sw As New StreamWriter(fs)
Dim s As String

Sub Main()
With ssh
.Hostname = 1.1.1.1
.Login = username
.Password = password
.Command = sh run & vbCrLf
.Protocol = ssh.SupportedProtocols.SSHAuto
.Encryption = ssh.EncryptionMethods.Auto
.Connect()
End With
Do

Loop Until ssh.State = WeOnlyDo.Client.SSH.States.Disconnected
End Sub

Private Sub ssh_DataReceivedEvent(ByVal Sender As Object, ByVal Args As WeOnlyDo.Client.SSH.DataReceivedArgs) Handles ssh.DataReceivedEvent
s = ssh.Receive
sw.Write(s)
End Sub

Private Sub ssh_DisconnectedEvent(ByVal Sender As Object, ByVal Args As System.EventArgs) Handles ssh.DisconnectedEvent
sw.Close()
fs.Close()
MsgBox(ssh.State.ToString, MsgBoxStyle.Information, disconnect event )
End Sub
End Module