Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
SSH Tunnel for Database Connection (such as ADO, ODBC, 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. Downloads: MS Windows Visual C/C++ Libraries Linux/CentOS C/C++ Libraries MAC OS X C/C++ Libraries Solaris C/C++ Libraries C++ Builder Libraries #include <C_CkSshTunnel.h> void ChilkatSample(void) { HCkSshTunnel sshTunnel; BOOL success; long listenPort; long maxWaitMs; sshTunnel = CkSshTunnel_Create(); success = CkSshTunnel_UnlockComponent(sshTunnel,"30-day trial"); if (success != TRUE) { printf("%s\n",CkSshTunnel_lastErrorText(sshTunnel)); return; } // 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. CkSshTunnel_putDestPort(sshTunnel,1433); CkSshTunnel_putDestHostname(sshTunnel,"myDbServer.com"); // Provide information about the location of the SSH server, // and the authentication to be used with it. This is the // login information for the SSH server (not the database server). CkSshTunnel_putSshHostname(sshTunnel,"192.168.1.108"); CkSshTunnel_putSshPort(sshTunnel,22); CkSshTunnel_putSshLogin(sshTunnel,"mySshLogin"); CkSshTunnel_putSshPassword(sshTunnel,"mySshPassword"); // 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. listenPort = 3316; success = CkSshTunnel_BeginAccepting(sshTunnel,listenPort); if (success != TRUE) { printf("%s\n",CkSshTunnel_lastErrorText(sshTunnel)); return; } // At this point you may connect to the database server through // the SSH tunnel. Your 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 your database code would go... // When you're finished with the database connection, you may // stop the background tunnel threads: // Stop the background thread that accepts new connections: success = CkSshTunnel_StopAccepting(sshTunnel); if (success != TRUE) { printf("%s\n",CkSshTunnel_lastErrorText(sshTunnel)); return; } // If any background tunnels are still in existence (and managed // by a single SSH tunnel pool background thread), stop them... maxWaitMs = 1000; success = CkSshTunnel_StopAllTunnels(sshTunnel,maxWaitMs); if (success != TRUE) { printf("%s\n",CkSshTunnel_lastErrorText(sshTunnel)); return; } CkSshTunnel_Dispose(sshTunnel); } |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.