Lianja
Lianja
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 Lianja Downloads
llSuccess = .F.
// 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".
loSsh = createobject("CkSsh")
lnSshPort = 22
llSuccess = loSsh.Connect("ssh.example.com",lnSshPort)
if (llSuccess = .F.) then
? loSsh.LastErrorText
release loSsh
return
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.
lcPassword = "mySshPassword"
llSuccess = loSsh.AuthenticatePw("mySshLogin",lcPassword)
if (llSuccess = .F.) then
? loSsh.LastErrorText
release loSsh
return
endif
lnChannelNum = loSsh.OpenSessionChannel()
if (lnChannelNum < 0) then
? loSsh.LastErrorText
release loSsh
return
endif
// Enumerate the active channels and report each one's number and type.
n = loSsh.NumOpenChannels
for i = 0 to n - 1
lnChNum = loSsh.GetChannelNumber(i)
lcChType = loSsh.GetChannelType(i)
if (loSsh.LastMethodSuccess = .F.) then
? loSsh.LastErrorText
release loSsh
return
endif
? "Channel " + str(lnChNum) + " is of type " + lcChType
next
loSsh.Disconnect()
release loSsh