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
(DataFlex) SSH Tunnel for Database Connection (such as ADO, ODBC, JDBC, etc.)Demonstrates how to create an SSH tunneling client in a background thread of your application. This makes it possible to SSH tunnel database connections without the need for separate software (such as PuTTY) to be running.
Use ChilkatAx-win32.pkg Procedure Test Handle hoChilkatGlob Boolean iSuccess Handle hoTunnel String sSshHostname Integer iSshPort Integer iListenPort Boolean iWaitForThreadExit String sTemp1 Get Create (RefClass(cComChilkatGlobal)) To hoChilkatGlob If (Not(IsComObjectCreated(hoChilkatGlob))) Begin Send CreateComObject of hoChilkatGlob End Get ComUnlockBundle Of hoChilkatGlob "Anything for 30-day trial." To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoChilkatGlob To sTemp1 Showln sTemp1 Procedure_Return End Get Create (RefClass(cComChilkatSshTunnel)) To hoTunnel If (Not(IsComObjectCreated(hoTunnel))) Begin Send CreateComObject of hoTunnel End Move "sftp.example.com" To sSshHostname Move 22 To iSshPort // Connect to an SSH server and establish the SSH tunnel: Get ComConnect Of hoTunnel sSshHostname iSshPort To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoTunnel To sTemp1 Showln sTemp1 Procedure_Return End // Authenticate with the SSH server via a login/password // or with a public key. // This example demonstrates SSH password authentication. Get ComAuthenticatePw Of hoTunnel "mySshLogin" "mySshPassword" To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoTunnel To sTemp1 Showln sTemp1 Procedure_Return End // The destination host/port is the database server. // The DestHostname may be the domain name or // IP address (in dotted decimal notation) of the database // server. Set ComDestPort Of hoTunnel To 1433 Set ComDestHostname Of hoTunnel To "myDbServer.com" // Start accepting connections in a background thread. // The SSH tunnels are autonomously run in a background // thread. There is one background thread for accepting // connections, and another for managing the tunnel pool. Move 3316 To iListenPort Get ComBeginAccepting Of hoTunnel iListenPort To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoTunnel To sTemp1 Showln sTemp1 Procedure_Return End // At this point the app may connect to the database server through // the SSH tunnel. The database connection string would // use "localhost" for the hostname and 3316 for the port. // We're not going to show the database coding here, // because it can vary depending on the API you're using // (ADO, ODBC, OLE DB, etc. ) // This is where the application's database code would go... // Stop the background listen/accept thread: Move True To iWaitForThreadExit Get ComStopAccepting Of hoTunnel iWaitForThreadExit To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoTunnel To sTemp1 Showln sTemp1 Procedure_Return End // Close the SSH tunnel (would also kick any remaining connected clients). Get ComCloseTunnel Of hoTunnel iWaitForThreadExit To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoTunnel To sTemp1 Showln sTemp1 Procedure_Return End End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.