Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PowerBuilder) SSH Keyboard AuthenticationDemonstrates how to implement keyboard authentication with an SSH server.
integer li_rc oleobject loo_Ssh string ls_Hostname integer li_Port integer li_Success string ls_XmlResponse oleobject loo_Xml // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. loo_Ssh = create oleobject // Use "Chilkat_9_5_0.Ssh" for versions of Chilkat < 10.0.0 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 // Set some timeouts, in milliseconds: loo_Ssh.ConnectTimeoutMs = 5000 loo_Ssh.IdleTimeoutMs = 15000 // Connect to the SSH server. // The standard SSH port = 22 // The hostname may be a hostname or IP address. ls_Hostname = "sftp.example.com" li_Port = 22 li_Success = loo_Ssh.Connect(ls_Hostname,li_Port) if li_Success <> 1 then Write-Debug loo_Ssh.LastErrorText destroy loo_Ssh return end if // Begin keyboard authentication.. ls_XmlResponse = loo_Ssh.StartKeyboardAuth("myLogin") if loo_Ssh.LastMethodSuccess <> 1 then Write-Debug loo_Ssh.LastErrorText destroy loo_Ssh return end if // If a user authentication banner was received, then your app // may display it prior to prompting for the password. Write-Debug "UserAuthBanner: " + loo_Ssh.UserAuthBanner loo_Xml = create oleobject // Use "Chilkat_9_5_0.Xml" for versions of Chilkat < 10.0.0 li_rc = loo_Xml.ConnectToNewObject("Chilkat.Xml") li_Success = loo_Xml.LoadXml(ls_XmlResponse) // Assume LoadXml succeeds for the example.. if loo_Xml.HasChildWithTag("success") = 1 then Write-Debug "No password required, already authenticated." destroy loo_Ssh destroy loo_Xml return end if if loo_Xml.HasChildWithTag("error") = 1 then Write-Debug "Authentication already failed." destroy loo_Ssh destroy loo_Xml return end if // See the online reference documentation for Chilkat SSH. // The XML returned by StartKeyboardAuth will contain an infoRequest // with one or more prompts that your application may choose to display. // Call ContinueKeyboardAuth, passing in the whatever information is requires (such as the password). // Typically, keyboard authentication requires one call to ContinueKeyboardAuth // using the password. Theoretically, the SSH server could prompt for additional pieces // of information. The authentication is completed when the XML returned contains // either a "success" or "error" child node. // This example asumes only one call to ContinueKeyboardAuth is required. ls_XmlResponse = loo_Ssh.ContinueKeyboardAuth("myPassword") if loo_Ssh.LastMethodSuccess <> 1 then Write-Debug loo_Ssh.LastErrorText destroy loo_Ssh destroy loo_Xml return end if li_Success = loo_Xml.LoadXml(ls_XmlResponse) // Assume LoadXml succeeds for the example.. if loo_Xml.HasChildWithTag("success") = 1 then Write-Debug "SSH Keyboard Authentication Successful!" destroy loo_Ssh destroy loo_Xml return end if if loo_Xml.HasChildWithTag("error") = 1 then Write-Debug "Authentication failed." destroy loo_Ssh destroy loo_Xml return end if destroy loo_Ssh destroy loo_Xml |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.