PowerBuilder
PowerBuilder
Request an SSH Subsystem
See more SSH Examples
Demonstrates the Chilkat Ssh.SendReqSubsystem method, which requests a predefined subsystem on a session channel. The first argument is the channel number and the second is the subsystem name. This example requests the sftp subsystem.
Background: A subsystem is a named service the server exposes over a channel instead of a shell command —
sftp is the familiar example, and netconf is common on network devices. After acceptance, the channel carries that protocol's data, exchanged with the ordinary channel send and receive methods. If the server rejects the subsystem, the channel normally stays open and can be reused for another request.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.SendReqSubsystem method, which requests a predefined subsystem on a
// session channel. The 1st argument is the channel number and the 2nd is the subsystem name.
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
// Request the "sftp" subsystem. A 1 return means the server accepted the request;
// subsequent protocol data is exchanged with the normal channel send and receive methods.
li_Success = loo_Ssh.SendReqSubsystem(li_ChannelNum,"sftp")
if li_Success = 0 then
Write-Debug loo_Ssh.LastErrorText
destroy loo_Ssh
return
end if
Write-Debug "Subsystem request accepted."
loo_Ssh.Disconnect()
destroy loo_Ssh