PowerBuilder
PowerBuilder
Open an SSH Session Channel
See more SSH Examples
Demonstrates the Chilkat Ssh.OpenSessionChannel method, which opens a new SSH session channel. It takes no arguments and returns the channel number, or -1 on failure. The transport must already be connected and authenticated.
Background: SSH multiplexes independent channels over one authenticated connection, and a session channel is the one used to run a command, start a shell, or invoke a subsystem. Opening the channel is only the container — nothing runs until you follow it with an
exec, shell, or subsystem request. Always test for a negative return rather than assuming success.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Ssh
integer li_SshPort
string ls_Password
integer li_ChannelNum
li_Success = 0
// Demonstrates the Ssh.OpenSessionChannel method, which opens a new SSH session channel. It
// takes no arguments and returns the channel number, or -1 on failure. The transport must
// already be connected and authenticated.
loo_Ssh = create oleobject
li_rc = loo_Ssh.ConnectToNewObject("Chilkat.Ssh")
if li_rc < 0 then
destroy loo_Ssh
MessageBox("Error","Connecting to COM object failed")
return
end if
li_SshPort = 22
li_Success = loo_Ssh.Connect("ssh.example.com",li_SshPort)
if li_Success = 0 then
Write-Debug loo_Ssh.LastErrorText
destroy loo_Ssh
return
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.
ls_Password = "mySshPassword"
li_Success = loo_Ssh.AuthenticatePw("mySshLogin",ls_Password)
if li_Success = 0 then
Write-Debug loo_Ssh.LastErrorText
destroy loo_Ssh
return
end if
// Open a session channel. A negative return value indicates failure.
li_ChannelNum = loo_Ssh.OpenSessionChannel()
if li_ChannelNum < 0 then
Write-Debug loo_Ssh.LastErrorText
destroy loo_Ssh
return
end if
Write-Debug "Opened session channel: " + string(li_ChannelNum)
// Opening the channel does not start a shell or command -- send an exec, shell, or subsystem
// request next.
loo_Ssh.Disconnect()
destroy loo_Ssh