Visual FoxPro
Visual FoxPro
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 Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loSsh
LOCAL lnSshPort
LOCAL lcPassword
LOCAL lcOutput
LOCAL loJson
lnSuccess = 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.
loSsh = CreateObject('Chilkat.Ssh')
lnSshPort = 22
lnSuccess = loSsh.Connect("ssh.example.com",lnSshPort)
IF (lnSuccess = 0) THEN
? loSsh.LastErrorText
RELEASE loSsh
CANCEL
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.
lcPassword = "mySshPassword"
lnSuccess = loSsh.AuthenticatePw("mySshLogin",lcPassword)
IF (lnSuccess = 0) THEN
? loSsh.LastErrorText
RELEASE loSsh
CANCEL
ENDIF
lcOutput = loSsh.QuickCommand("uname -a","utf-8")
IF (loSsh.LastMethodSuccess = 0) THEN
? loSsh.LastErrorText
RELEASE loSsh
CANCEL
ENDIF
? lcOutput
* 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.
loJson = CreateObject('Chilkat.JsonObject')
loSsh.GetLastJsonData(loJson)
loJson.EmitCompact = 0
? loJson.Emit()
loSsh.Disconnect()
RELEASE loSsh
RELEASE loJson