Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Delphi ActiveXDelphi DLLVisual FoxProJavaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerShellPythonRubySQL ServerUnicode CUnicode C++Visual Basic 6.0VB.NETVBScript

C# Examples

Certificates
Email Object
Encryption
FTP
HTML-to-XML/Text
Gzip
HTTP
IMAP
MHT / HTML Email
POP3
RSA Encryption
MIME
SMTP
Socket/SSL/TLS
SSH Key
SSH
SFTP
Tar Archive
XML
XMP
Zip

More Examples...
Amazon S3
Bounced Email
CSV
Diffie-Hellman
NTLM

 

 

 

 

 

 

 

(C#) 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.

Chilkat .NET Downloads

Chilkat .NET Assemblies

Chilkat.SshTunnel sshTunnel = new Chilkat.SshTunnel();

bool success;
success = sshTunnel.UnlockComponent("30-day trial");
if (success != true) {
    textBox1.Text += sshTunnel.LastErrorText + "\r\n";
    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.
sshTunnel.DestPort = 1433;
sshTunnel.DestHostname = "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).
sshTunnel.SshHostname = "192.168.1.108";
sshTunnel.SshPort = 22;
sshTunnel.SshLogin = "mySshLogin";
sshTunnel.SshPassword = "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.
int listenPort;
listenPort = 3316;
success = sshTunnel.BeginAccepting(listenPort);
if (success != true) {
    MessageBox.Show(sshTunnel.LastErrorText);
    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 = sshTunnel.StopAccepting();
if (success != true) {
    textBox1.Text += sshTunnel.LastErrorText + "\r\n";
    return;
}

//  If any background tunnels are still in existence (and managed
//  by a single SSH tunnel pool background thread), stop them...
int maxWaitMs;
maxWaitMs = 1000;
success = sshTunnel.StopAllTunnels(maxWaitMs);
if (success != true) {
    textBox1.Text += sshTunnel.LastErrorText + "\r\n";
    return;
}

 

© 2000-2014 Chilkat Software, Inc. All Rights Reserved.