Visual C++ Examples

ChilkatHOMEAndroid™Classic ASPCC++C#C# WinRTDelphi ActiveXDelphi DLLVisual FoxProJavaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerShellPythonRubySQL ServerUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET WinRTVBScript

C++ Examples

CkString
Byte Array
Bounced Mail
Bz2
Character Encoding
CSV
DH Key Exchange
DKIM/DomainKeys
Digital Certificates
Digital Signatures
DSA
Email
Email Object
Encryption
FTP
HTML Conversion
HTTP
IMAP
MHT / HTML Email
POP3
RSA
S/MIME
SMTP
Socket
Spider
SSH Key
SSH
SSH Tunnel
SFTP
Tar
Upload
XML
XMP
Zip Compression


More Examples...
Amazon S3
NTLM
FileAccess
RSS
Atom
Self-Extractor
Service
PPMD
Deflate
Bzip2
LZW

 

 

 

 

 

 

 

 

SSH Tunnel using an HTTP proxy

Demonstrates how to establish an SSH tunnel that uses an HTTP proxy.

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
FreeBSD C++ Libraries
HP-UX C++ Libraries
BlackBerry QNX C++ Libraries
#include <CkSshTunnel.h>

void ChilkatSample(void)
    {
    CkSshTunnel sshTunnel;

    bool success;
    success = sshTunnel.UnlockComponent("30-day trial");
    if (success != true) {
        printf("%s\n",sshTunnel.lastErrorText());
        return;
    }

    //  The DestHostname / DestPort is the server with which we
    //  are ultimately communicating.
    sshTunnel.put_DestPort(1433);
    sshTunnel.put_DestHostname("myServer.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.
    sshTunnel.put_SshHostname("192.168.1.108");
    sshTunnel.put_SshPort(22);
    sshTunnel.put_SshLogin("mySshLogin");
    sshTunnel.put_SshPassword("mySshPassword");

    //  To connect through an HTTP proxy, set the HttpProxyHostname
    //  and HttpProxyPort properties to the hostname (or IP address)
    //  and port of the HTTP proxy.  Typical port numbers used by
    //  HTTP proxy servers are 3128 and 8080.
    sshTunnel.put_HttpProxyHostname("www.my-http-proxy.com");
    sshTunnel.put_HttpProxyPort(3128);

    //  Important:  Your HTTP proxy server must allow non-HTTP
    //  traffic to pass.  Otherwise this does not work.

    //  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.
    long listenPort;
    listenPort = 3316;
    success = sshTunnel.BeginAccepting(listenPort);
    if (success != true) {
        printf("%s\n",sshTunnel.lastErrorText());
        return;
    }

    //  At this point you may write code to communicate with
    //  the server at DestHostname/DestPort.  This could be anything --
    //  it could be WinSock, ADO/ODBC code, Chilkat Socket, etc.
    //  However, instead of connecting directly to DestHostname/DestPort,
    //  your code would connect to localhost:3316 (because this
    //  is the listenPort of the SSH Tunnel

    //  This is what happens when you connect to localhost:3316
    //  1) The connection is accepted by the SSH tunnel
    //      background thread (which was started in the call to BeginAccepting).
    //  2) In the background thread, a connection to a remote SSH
    //      server is established via an HTTP proxy.
    //  3) Port-forwarding is setup so that the remote SSH server connects
    //     to the DestHostname/DestPort.
    //  4) Data sent by your application to localhost:3316 is ultimately forwarded to DestHostname/DestPort
    //   5) Data sent back from DestHostname/DestPort is forwarded back and received by your application

    //  When you're finished with the  connection, you may
    //  stop the background tunnel threads:
    //  Stop the background thread that accepts new connections:
    success = sshTunnel.StopAccepting();
    if (success != true) {
        printf("%s\n",sshTunnel.lastErrorText());
        return;
    }

    //  If any background tunnels are still in existence (and managed
    //  by a single SSH tunnel pool background thread), stop them...
    long maxWaitMs;
    maxWaitMs = 1000;
    success = sshTunnel.StopAllTunnels(maxWaitMs);
    if (success != true) {
        printf("%s\n",sshTunnel.lastErrorText());
        return;
    }

    }

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