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
(Visual FoxPro) REST through SSH TunnelDemonstrates how to connect through an SSH Tunnel (via port-forwarding) to make REST API calls.
LOCAL loTunnel LOCAL lcSshHostname LOCAL lnSshPort LOCAL lnSuccess LOCAL loRest LOCAL loChannel LOCAL lnBTls LOCAL lnPort LOCAL lnMaxWaitMs LOCAL loAuthAws LOCAL lcResponseXml LOCAL loXml * This example requires the Chilkat API to have been previously unlocked. * See Global Unlock Sample for sample code. * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Socket') loTunnel = CreateObject('Chilkat.Socket') lcSshHostname = "sftp.example.com" lnSshPort = 22 * Connect to an SSH server and establish the SSH tunnel: lnSuccess = loTunnel.SshOpenTunnel(lcSshHostname,lnSshPort) IF (lnSuccess <> 1) THEN ? loTunnel.LastErrorText RELEASE loTunnel CANCEL ENDIF * Authenticate with the SSH server via a login/password * or with a public key. * This example demonstrates SSH password authentication. lnSuccess = loTunnel.SshAuthenticatePw("mySshLogin","mySshPassword") IF (lnSuccess <> 1) THEN ? loTunnel.LastErrorText RELEASE loTunnel CANCEL ENDIF * OK, the SSH tunnel is setup. Now open a channel within the tunnel. * (Any number of channels may be created from the same SSH tunnel. * Multiple channels may coexist at the same time.) * This example connects to a REST server through the SSH tunnel. * It will connect to the Amazon AWS service for this example. * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Rest') loRest = CreateObject('Chilkat.Rest') lnBTls = 1 lnPort = 443 lnMaxWaitMs = 5000 * This returns a socket object that is a single channel within the SSH tunnel. loChannel = loTunnel.SshOpenChannel("s3.amazonaws.com",lnPort,lnBTls,lnMaxWaitMs) IF (loTunnel.LastMethodSuccess <> 1) THEN ? loTunnel.LastErrorText RELEASE loTunnel RELEASE loRest CANCEL ENDIF * Use the connection. (This connection is a TLS running on an SSH channel through an SSH tunnel. * In other words, TLS is wrapped within the SSH tunnel.) lnSuccess = loRest.UseConnection(loChannel,1) IF (lnSuccess <> 1) THEN ? loRest.LastErrorText RELEASE loChannel RELEASE loTunnel RELEASE loRest CANCEL ENDIF * Provide AWS credentials for the REST call. * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.AuthAws') loAuthAws = CreateObject('Chilkat.AuthAws') loAuthAws.AccessKey = "AWS_ACCESS_KEY" loAuthAws.SecretKey = "AWS_SECRET_KEY" loAuthAws.ServiceName = "s3" lnSuccess = loRest.SetAuthAws(loAuthAws) * List all buckets for the account... lcResponseXml = loRest.FullRequestNoBody("GET","/") IF (loRest.LastMethodSuccess <> 1) THEN ? loRest.LastErrorText RELEASE loChannel RELEASE loTunnel RELEASE loRest RELEASE loAuthAws CANCEL ENDIF * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Xml') loXml = CreateObject('Chilkat.Xml') lnSuccess = loXml.LoadXml(lcResponseXml) * Show the full XML returned. ? loXml.GetXml() * Iterate over the buckets, showing each bucket name. lnSuccess = loXml.FindChild2("Buckets") IF (loXml.FirstChild2() = 1) THEN ? loXml.GetChildContent("Name") DO WHILE (loXml.NextSibling2() = 1) ? loXml.GetChildContent("Name") ENDDO ENDIF * Move the internal pointer back to the root node. loXml.GetRoot2() RELEASE loChannel RELEASE loTunnel RELEASE loRest RELEASE loAuthAws RELEASE loXml |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.