Sample code for 30+ languages & platforms
Xojo Plugin

Get Diagnostic JSON from the Last SSH Method Call

See more SSH Examples

Demonstrates the Chilkat Ssh.GetLastJsonData method, which copies structured diagnostic information from the most recently called method into a JsonObject. The only argument is the JsonObject that receives the information.

Background: This gives machine-readable diagnostics as an alternative to parsing LastErrorText, which is useful for logging or automated error handling. Many methods produce little or no additional JSON, so expect an object that is sometimes nearly empty. Authentication passwords and private-key passphrases are never included, so the output is safe to log.

Chilkat Xojo Plugin Downloads

Xojo Plugin
Dim success As Boolean
success = False

//  Demonstrates the Ssh.GetLastJsonData method, which copies structured diagnostic information
//  from the most recently called method into a JsonObject.  The only argument is the JsonObject
//  that receives the information.

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

Dim output As String
output = ssh.QuickCommand("uname -a","utf-8")
If (ssh.LastMethodSuccess = False) Then
    System.DebugLog(ssh.LastErrorText)
    Return
End If

System.DebugLog(output)

//  Retrieve diagnostic details about the call that was just made.  Many methods produce little
//  or no additional JSON.  Passwords and private-key passphrases are never included.
Dim json As New Chilkat.JsonObject
ssh.GetLastJsonData json

json.EmitCompact = False
System.DebugLog(json.Emit())

ssh.Disconnect