Xojo Plugin
Xojo Plugin
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 Xojo Plugin Downloads
Dim success As Boolean
success = False
// 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.
Dim ssh As New Chilkat.Ssh
Dim sshPort As Int32
sshPort = 22
success = ssh.Connect("ssh.example.com",sshPort)
If (success = False) Then
System.DebugLog(ssh.LastErrorText)
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.
Dim password As String
password = "mySshPassword"
success = ssh.AuthenticatePw("mySshLogin",password)
If (success = False) Then
System.DebugLog(ssh.LastErrorText)
Return
End If
// Start three commands without waiting for any of them to finish.
Dim channel1 As Int32
channel1 = ssh.QuickCmdSend("sleep 2; echo first done")
If (channel1 < 0) Then
System.DebugLog(ssh.LastErrorText)
Return
End If
Dim channel2 As Int32
channel2 = ssh.QuickCmdSend("echo second done")
If (channel2 < 0) Then
System.DebugLog(ssh.LastErrorText)
Return
End If
Dim channel3 As Int32
channel3 = ssh.QuickCmdSend("sleep 1; echo third done")
If (channel3 < 0) Then
System.DebugLog(ssh.LastErrorText)
Return
End If
System.DebugLog("Started three concurrent commands.")
// Use QuickCmdCheck to collect the results as each command completes.
ssh.Disconnect