PowerBuilder
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Ssh
integer li_SshPort
string ls_Password
string ls_Output
oleobject loo_Json
li_Success = 0
// 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.
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
ls_Output = loo_Ssh.QuickCommand("uname -a","utf-8")
if loo_Ssh.LastMethodSuccess = 0 then
Write-Debug loo_Ssh.LastErrorText
destroy loo_Ssh
return
end if
Write-Debug ls_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.
loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
loo_Ssh.GetLastJsonData(loo_Json)
loo_Json.EmitCompact = 0
Write-Debug loo_Json.Emit()
loo_Ssh.Disconnect()
destroy loo_Ssh
destroy loo_Json