Sample code for 30+ languages & platforms
PowerBuilder

Open a Custom SSH Channel Type

See more SSH Examples

Demonstrates the Chilkat Ssh.OpenCustomChannel method, which requests a channel whose application-defined type is supplied as the only argument. It returns the channel number, or -1 if the server rejects the channel. The server must implement that channel type.

Background: The SSH protocol allows vendor- and application-specific channel types beyond the standard session and direct-tcpip kinds; by convention these carry an @domain suffix to avoid name collisions. This method is the escape hatch for talking to a server that implements such a type. On rejection, inspect ChannelOpenFailCode to learn why.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Ssh
integer li_SshPort
string ls_Password
string ls_ChannelType
integer li_ChannelNum

li_Success = 0

//  Demonstrates the Ssh.OpenCustomChannel method, which requests a custom SSH channel whose
//  application-defined type is supplied as the only argument.  It returns the channel number,
//  or -1 if the server rejects the channel.  The server must implement that channel type.

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

//  Request an application-defined channel type.  The server must support it.
ls_ChannelType = "my-custom-channel@example.com"
li_ChannelNum = loo_Ssh.OpenCustomChannel(ls_ChannelType)
if li_ChannelNum < 0 then
    Write-Debug loo_Ssh.LastErrorText
    destroy loo_Ssh
    return
end if

Write-Debug "Opened custom channel: " + string(li_ChannelNum)

//  The channel is used with the normal channel send, receive, EOF, CLOSE, and release methods.

loo_Ssh.Disconnect()


destroy loo_Ssh