PowerBuilder
PowerBuilder
Start Concurrent SSH Commands with QuickCmdSend
See more SSH Examples
Demonstrates the Chilkat Ssh.QuickCmdSend method, which starts a remote command and immediately returns its channel number. The only argument is the command line. Internally it opens a session channel and sends an exec request.
Background: Because it returns without waiting, several commands can run concurrently over one authenticated connection — far faster than running them one after another when each has latency or slow work to do. Pair it with
QuickCmdCheck, which reports commands as they finish, so results can be collected in completion order rather than the order they were started.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Ssh
integer li_SshPort
string ls_Password
integer li_Channel1
integer li_Channel2
integer li_Channel3
li_Success = 0
// Demonstrates the Ssh.QuickCmdSend method, which starts a remote command and immediately
// returns its channel number. The only argument is the command line. Because it returns
// right away, several commands can run concurrently on the same SSH connection.
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
// Start three commands without waiting for any of them to finish.
li_Channel1 = loo_Ssh.QuickCmdSend("sleep 2; echo first done")
if li_Channel1 < 0 then
Write-Debug loo_Ssh.LastErrorText
destroy loo_Ssh
return
end if
li_Channel2 = loo_Ssh.QuickCmdSend("echo second done")
if li_Channel2 < 0 then
Write-Debug loo_Ssh.LastErrorText
destroy loo_Ssh
return
end if
li_Channel3 = loo_Ssh.QuickCmdSend("sleep 1; echo third done")
if li_Channel3 < 0 then
Write-Debug loo_Ssh.LastErrorText
destroy loo_Ssh
return
end if
Write-Debug "Started three concurrent commands."
// Use QuickCmdCheck to collect the results as each command completes.
loo_Ssh.Disconnect()
destroy loo_Ssh