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 using an HTTP proxyDemonstrates how to establish an SSH tunnel that uses an HTTP proxy. CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int DECLARE @sTmp0 nvarchar(4000) DECLARE @sshTunnel int EXEC @hr = sp_OACreate 'Chilkat.SshTunnel', @sshTunnel OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END DECLARE @success int EXEC sp_OAMethod @sshTunnel, 'UnlockComponent', @success OUT, '30-day trial' IF @success <> 1 BEGIN EXEC sp_OAGetProperty @sshTunnel, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END -- The DestHostname / DestPort is the server with which we -- are ultimately communicating. EXEC sp_OASetProperty @sshTunnel, 'DestPort', 1433 EXEC sp_OASetProperty @sshTunnel, '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. EXEC sp_OASetProperty @sshTunnel, 'SshHostname', '192.168.1.108' EXEC sp_OASetProperty @sshTunnel, 'SshPort', 22 EXEC sp_OASetProperty @sshTunnel, 'SshLogin', 'mySshLogin' EXEC sp_OASetProperty @sshTunnel, '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. EXEC sp_OASetProperty @sshTunnel, 'HttpProxyHostname', 'www.my-http-proxy.com' EXEC sp_OASetProperty @sshTunnel, '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. DECLARE @listenPort int SELECT @listenPort = 3316 EXEC sp_OAMethod @sshTunnel, 'BeginAccepting', @success OUT, @listenPort IF @success <> 1 BEGIN EXEC sp_OAGetProperty @sshTunnel, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END -- 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: EXEC sp_OAMethod @sshTunnel, 'StopAccepting', @success OUT IF @success <> 1 BEGIN EXEC sp_OAGetProperty @sshTunnel, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END -- If any background tunnels are still in existence (and managed -- by a single SSH tunnel pool background thread), stop them... DECLARE @maxWaitMs int SELECT @maxWaitMs = 1000 EXEC sp_OAMethod @sshTunnel, 'StopAllTunnels', @success OUT, @maxWaitMs IF @success <> 1 BEGIN EXEC sp_OAGetProperty @sshTunnel, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END END GO |
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.