SSH ActiveX

I am trying to pull data from a Unix SSH Server on a Windows Machine.

For this i installed 2 ActiveX Controls (Chilkat SSH and SSH ActiveX). But until now, i can’t get it to work. :frowning:

I managed to receive the welcome message with the Chilkat Control, but i can’t send a command and receive the response from the Server. And if i try to use the second SSH-ActiveX solution as an OleObject, my app crashes.

Has anybody managed to use SSH with Xojo and can help me here with a short code example please?

Have you tried the open free Telnet classes for Xojo? Much easier to use than ActiveX COMs and is cross-platform. I’ve used them to access SSH from windows to Linux.

No. And i would love to avoid paying 149$, because i am a hobby dev. and do most stuff for my own “pleasure” :slight_smile:

Would you please be so kind and point me to the Telnet Classes and provide a simple Code Snippet? That would be awesome. :slight_smile:

I got it now working, using the Chilkat ActiveX Control. For my tests i have a Windows with a TextArea, a Thread, a Timer, a few Properties and 3 PushButtons.
The first Button opens the connection:

[code] ssh.DebugLogFilePath = f.NativePath
Dim cmdOutput As String
success = ssh.UnlockComponent(“Anything for 30-day trial”)
If (success <> 1) Then
TextArea1.AppendText ssh.LastErrorText + EndOfLine + " >>>>>>>>>>>>>>>>>>>>>>>>>> " + EndOfLine
TextArea1.AppendText “SSH Plugin registered…” + EndOfLine
End If

success = ssh.Connect(myIPAdress,22)
If (success <> 1) Then
MsgBox ssh.LastErrorText
TextArea1.AppendText “Connected…” + EndOfLine
End If

// Wait a max of 5 seconds when reading responses…
ssh.IdleTimeoutMs = 5000
ssh.VerboseLogging = 1

// Authenticate using login/password:
success = ssh.AuthenticatePw(myLogin,myPassword
If (success <> 1) Then
MsgBox ssh.LastErrorText
TextArea1.AppendText “Logged in…” + EndOfLine
End If

// Open a session channel. (It is possible to have multiple
// session channels open simultaneously.)

channelNum = ssh.OpenSessionChannel()
If (channelNum < 0) Then
TextArea1.AppendText ssh.LastErrorText + EndOfLine + " >>>>>>>>>>>>>>>>>>>>>>>>>> " + EndOfLine
TextArea1.AppendText “Channel opened…” + EndOfLine
End If

’ Some SSH servers require a pseudo-terminal
’ If so, include the call to SendReqPty. If not, then
’ comment out the call to SendReqPty.
’ Note: The 2nd argument of SendReqPty is the terminal type,
’ which should be something like “xterm”, “vt100”, “dumb”, etc.
’ A “dumb” terminal is one that cannot process escape sequences.
’ Smart terminals, such as “xterm”, “vt100”, etc. process
’ escape sequences. If you select a type of smart terminal,
’ your application will receive these escape sequences
’ included in the command’s output. Use “dumb” if you do not
’ want to receive escape sequences. (Assuming your SSH
’ server recognizes “dumb” as a standard dumb terminal.)
Dim termType As String
termType = “dumb”
Dim widthInChars As Integer
widthInChars = 120
Dim heightInChars As Integer
heightInChars = 40
’ Use 0 for pixWidth and pixHeight when the dimensions
’ are set in number-of-chars.
Dim pixWidth As Integer
pixWidth = 0
Dim pixHeight As Integer
pixHeight = 0
success = ssh.SendReqPty(channelNum,termType,widthInChars,heightInChars,pixWidth,pixHeight)
If (success <> 1) Then
TextArea1.AppendText ssh.LastErrorText + EndOfLine
TextArea1.AppendText “Terminal started…” + EndOfLine
End If

’ Start a shell on the channel:
success = ssh.SendReqShell(channelNum)
If (success <> 1) Then
TextArea1.AppendText ssh.LastErrorText + EndOfLine
TextArea1.AppendText “Session opened…” + EndOfLine
End If[/code]

The 2nd Button sends a command:

[code] ’ Start a command in the remote shell. This example
’ will send a “ls” command to retrieve the directory listing.
success = ssh.ChannelSendString(channelNum,“show xdsl operational-data line 1/1/1/1 xml” + EndOfLine.UNIX,“utf-8”)
If (success <> 1) Then
MsgBox ssh.LastErrorText
End If

’ Send an EOF. This tells the server that no more data will
’ be sent on this channel. The channel remains open, and
’ the SSH client may still receive output on this channel.
// success = ssh.ChannelSendEof(channelNum)
// If (success <> 1) Then
// MsgBox ssh.LastErrorText
// End If


Then i pull the received server response in a Thread:

[code] WeitereDaten = ssh.ChannelReadAndPoll(channelNum,2000)
If WeitereDaten > -1 Then
Timer1.Mode = 2
While WeitereDaten >0
If ssh<>Nil Then
cmdOutput = ssh.GetReceivedText(channelNum,“utf-8”)
If cmdOutput <> “” Then
DerText = DerText + cmdOutput
End If
End If
End If


In a Timer, i write the received server response to the TextArea:

[code] If Thread1<>Nil Then
TextArea1.AppendText DerText
Me.Mode = 0

DerText = ""

End If[/code]

The 3rd Button just disconnects:

' Disconnect Timer1.Mode = 0 ssh.Disconnect TextArea1.AppendText "Disconnected" + EndOfLine

This “example” is far from beeing well done, but it shows how to make it work (essentially). :slight_smile:

But i would still prefer a solution which is cross plattform and which would avoid paying for an ActiveX Control… :slight_smile:

Here is the telnet class developed by @Mike Cotrone

In case you or anyone else finds need to implement SSH without any dependencies.

BTW: Can someone please move this Thread into another Queue? I placed it in “Customer Service” by accident… Thank you

You’ll need to write to Norman or one of the admins to change channel in case they don’t see your post. You don’t have a change channel option at the top next to the channel (i have that option for my own conversations)

I already moved it :slight_smile: