Sample code for 30+ languages & platforms
Visual Basic 6.0

Get the Type of an Active SSH Channel

See more SSH Examples

Demonstrates the Chilkat Ssh.GetChannelType method, which returns the type of the channel at a zero-based enumeration index. The only argument is the index — an enumeration position, not a channel number. Values include session, x11, forwarded-tcpip, and direct-tcpip.

Background: Paired with GetChannelNumber, this turns the channel collection into a readable inventory of what a connection is currently doing — which channels are running commands (session) versus tunneling TCP traffic (direct-tcpip). That is valuable for diagnostics and for application code that manages several channel kinds at once. An out-of-range index causes the string-returning method to report failure.

Chilkat Visual Basic 6.0 Downloads

Visual Basic 6.0
Dim success As Long
success = 0

'  Demonstrates the Ssh.GetChannelType method, which returns the type of the channel at a
'  zero-based enumeration index.  The only argument is the index, which is an enumeration
'  position and not a channel number.  Values include "session" and "direct-tcpip".

Dim ssh As New ChilkatSsh

Dim sshPort As Long
sshPort = 22
success = ssh.Connect("ssh.example.com",sshPort)
If (success = 0) Then
    Debug.Print ssh.LastErrorText
    Exit Sub
End If

'  Normally you would not hard-code the password in source.  You should instead obtain it
'  from an interactive prompt, environment variable, or a secrets vault.
Dim password As String
password = "mySshPassword"

success = ssh.AuthenticatePw("mySshLogin",password)
If (success = 0) Then
    Debug.Print ssh.LastErrorText
    Exit Sub
End If

Dim channelNum As Long
channelNum = ssh.OpenSessionChannel()
If (channelNum < 0) Then
    Debug.Print ssh.LastErrorText
    Exit Sub
End If

'  Enumerate the active channels and report each one's number and type.
Dim n As Long
n = ssh.NumOpenChannels
Dim i As Long
For i = 0 To n - 1
    Dim chNum As Long
    chNum = ssh.GetChannelNumber(i)
    Dim chType As String
    chType = ssh.GetChannelType(i)
    If (ssh.LastMethodSuccess = 0) Then
        Debug.Print ssh.LastErrorText
        Exit Sub
    End If

    Debug.Print "Channel " & chNum & " is of type " & chType
Next

ssh.Disconnect