AutoIt
AutoIt
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 AutoIt Downloads
Local $bSuccess = False
; 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".
$oSsh = ObjCreate("Chilkat.Ssh")
Local $iSshPort = 22
$bSuccess = $oSsh.Connect("ssh.example.com",$iSshPort)
If ($bSuccess = False) Then
ConsoleWrite($oSsh.LastErrorText & @CRLF)
Exit
EndIf
; 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.
Local $sPassword = "mySshPassword"
$bSuccess = $oSsh.AuthenticatePw("mySshLogin",$sPassword)
If ($bSuccess = False) Then
ConsoleWrite($oSsh.LastErrorText & @CRLF)
Exit
EndIf
Local $iChannelNum = $oSsh.OpenSessionChannel()
If ($iChannelNum < 0) Then
ConsoleWrite($oSsh.LastErrorText & @CRLF)
Exit
EndIf
; Enumerate the active channels and report each one's number and type.
Local $iN = $oSsh.NumOpenChannels
Local $i
For $i = 0 To $iN - 1
Local $iChNum = $oSsh.GetChannelNumber($i)
Local $sChType = $oSsh.GetChannelType($i)
If ($oSsh.LastMethodSuccess = False) Then
ConsoleWrite($oSsh.LastErrorText & @CRLF)
Exit
EndIf
ConsoleWrite("Channel " & $iChNum & " is of type " & $sChType & @CRLF)
Next
$oSsh.Disconnect