Sample code for 30+ languages & platforms
AutoIt

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 AutoIt Downloads

AutoIt
Local $bSuccess = 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.

$oSsh = ObjCreate("Chilkat.Ssh")

Local $iSshPort = 22
$bSuccess = $oSsh.Connect("ssh.example.com",$iSshPort)
If ($bSuccess = False) Then
    ConsoleWrite($oSsh.LastErrorText & @CRLF)
    Exit
EndIf

;  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.
Local $sPassword = "mySshPassword"

$bSuccess = $oSsh.AuthenticatePw("mySshLogin",$sPassword)
If ($bSuccess = False) Then
    ConsoleWrite($oSsh.LastErrorText & @CRLF)
    Exit
EndIf

Local $sOutput = $oSsh.QuickCommand("uname -a","utf-8")
If ($oSsh.LastMethodSuccess = False) Then
    ConsoleWrite($oSsh.LastErrorText & @CRLF)
    Exit
EndIf

ConsoleWrite($sOutput & @CRLF)

;  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.
$oJson = ObjCreate("Chilkat.JsonObject")
$oSsh.GetLastJsonData $oJson

$oJson.EmitCompact = False
ConsoleWrite($oJson.Emit() & @CRLF)

$oSsh.Disconnect