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
(Tcl) REST through SSH TunnelDemonstrates how to connect through an SSH Tunnel (via port-forwarding) to make REST API calls.
load ./chilkat.dll # This example requires the Chilkat API to have been previously unlocked. # See Global Unlock Sample for sample code. set tunnel [new_CkSocket] set sshHostname "sftp.example.com" set sshPort 22 # Connect to an SSH server and establish the SSH tunnel: set success [CkSocket_SshOpenTunnel $tunnel $sshHostname $sshPort] if {$success != 1} then { puts [CkSocket_lastErrorText $tunnel] delete_CkSocket $tunnel exit } # Authenticate with the SSH server via a login/password # or with a public key. # This example demonstrates SSH password authentication. set success [CkSocket_SshAuthenticatePw $tunnel "mySshLogin" "mySshPassword"] if {$success != 1} then { puts [CkSocket_lastErrorText $tunnel] delete_CkSocket $tunnel exit } # 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. set rest [new_CkRest] # channel is a CkSocket set bTls 1 set port 443 set maxWaitMs 5000 # This returns a socket object that is a single channel within the SSH tunnel. set channel [CkSocket_SshOpenChannel $tunnel "s3.amazonaws.com" $port $bTls $maxWaitMs] if {[CkSocket_get_LastMethodSuccess $tunnel] != 1} then { puts [CkSocket_lastErrorText $tunnel] delete_CkSocket $tunnel delete_CkRest $rest exit } # 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.) set success [CkRest_UseConnection $rest $channel 1] if {$success != 1} then { puts [CkRest_lastErrorText $rest] delete_CkSocket $channel delete_CkSocket $tunnel delete_CkRest $rest exit } # Provide AWS credentials for the REST call. set authAws [new_CkAuthAws] CkAuthAws_put_AccessKey $authAws "AWS_ACCESS_KEY" CkAuthAws_put_SecretKey $authAws "AWS_SECRET_KEY" CkAuthAws_put_ServiceName $authAws "s3" set success [CkRest_SetAuthAws $rest $authAws] # List all buckets for the account... set responseXml [CkRest_fullRequestNoBody $rest "GET" "/"] if {[CkRest_get_LastMethodSuccess $rest] != 1} then { puts [CkRest_lastErrorText $rest] delete_CkSocket $channel delete_CkSocket $tunnel delete_CkRest $rest delete_CkAuthAws $authAws exit } set xml [new_CkXml] set success [CkXml_LoadXml $xml $responseXml] # Show the full XML returned. puts [CkXml_getXml $xml] # Iterate over the buckets, showing each bucket name. set success [CkXml_FindChild2 $xml "Buckets"] if {[CkXml_FirstChild2 $xml] == 1} then { puts [CkXml_getChildContent $xml Name] while {[CkXml_NextSibling2 $xml] == 1} { puts [CkXml_getChildContent $xml Name] } } # Move the internal pointer back to the root node. CkXml_GetRoot2 $xml delete_CkSocket $channel delete_CkSocket $tunnel delete_CkRest $rest delete_CkAuthAws $authAws delete_CkXml $xml |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.