Rebex SSH Shell
SSH shell, tunneling, telnet, ANSI terminal emulation library for .NET
Download 30-day free trial Buy from $699More .NET libraries
-
Rebex SFTP
SFTP client
-
Rebex SSH Pack
SSH Shell + SFTP + SSH server
-
Rebex Total Pack
All Rebex .NET libraries together
Back to feature list...
Proxies and custom sockets
On this page:
SOCKS4/SOCKS5 proxy servers
To connect through SOCKET4, SOCKET4a or SOCKS5 proxy servers, set Ssh.Proxy
properties
before calling the Connect
method. Use ProxyType
property to specify the proxy type:
// create SSH client instance
var ssh = new Rebex.Net.Ssh();
// use SOCKS5 proxy
ssh.Proxy.ProxyType = ProxyType.Socks5;
ssh.Proxy.Host = proxyHost;
ssh.Proxy.Port = proxyPort;
ssh.Proxy.UserName = proxyUserName;
// connect to the server
ssh.Connect(hostname);
' create SSH client instance
Dim ssh = New Rebex.Net.Ssh()
' use SOCKS5 proxy
ssh.Proxy.ProxyType = ProxyType.Socks5
ssh.Proxy.Host = proxyHost
ssh.Proxy.Port = proxyPort
ssh.Proxy.UserName = proxyUserName
' connect to the server
ssh.Connect(hostname)
HTTP CONNECT proxy servers
To connect through a HTTP proxy server, set Ssh.Proxy
properties
before calling the Connect
method. Make sure the proxy server supports HTTP CONNECT method,
and set the ProxyType
property to HttpConnect
:
// create SSH client instance
var ssh = new Rebex.Net.Ssh();
// use HTTP CONNECT proxy
ssh.Proxy.ProxyType = ProxyType.HttpConnect;
ssh.Proxy.Host = proxyHost;
ssh.Proxy.Port = proxyPort;
ssh.Proxy.UserName = proxyUserName;
ssh.Proxy.Password = proxyPassword;
// connect to the server
ssh.Connect(hostname);
' create SSH client instance
Dim ssh = New Rebex.Net.Ssh()
' use HTTP CONNECT proxy
ssh.Proxy.ProxyType = ProxyType.HttpConnect
ssh.Proxy.Host = proxyHost
ssh.Proxy.Port = proxyPort
ssh.Proxy.UserName = proxyUserName
ssh.Proxy.Password = proxyPassword
' connect to the server
ssh.Connect(hostname)
Proxies with single sign-on
Some HTTP CONNECT proxies support NTLM authentication with single sign-on. To take advantage of this
feature, set the AuthenticationMethod
property to ProxyAuthentication.Ntlm
.
// create SSH client instance
var ssh = new Rebex.Net.Ssh();
// use HTTP CONNECT proxy
ssh.Proxy.ProxyType = ProxyType.HttpConnect;
ssh.Proxy.Host = proxyHost;
ssh.Proxy.Port = proxyPort;
// use single sign-on
ssh.Proxy.AuthenticationMethod = ProxyAuthentication.Ntlm;
// connect to the server
ssh.Connect(hostname);
' create SSH client instance
Dim ssh = New Rebex.Net.Ssh()
' use HTTP CONNECT proxy
ssh.Proxy.ProxyType = ProxyType.HttpConnect
ssh.Proxy.Host = proxyHost
ssh.Proxy.Port = proxyPort
' use single sign-on
ssh.Proxy.AuthenticationMethod = ProxyAuthentication.Ntlm
' connect to the server
ssh.Connect(hostname)
SSH server as proxy
It's possible to tunnel SSH sessions through an SSH server, essentially using it as a proxy server. See Tunneling for more information and sample code.
Custom transport layer - ISocket
Rebex libraries make it possible to implement a custom transport layer,
giving you full control over the network communication.
All you need to do is implement a custom ISocketFactory
and
ISocket
interfaces and instruct the Ssh
object to use them.
// create SSH client instance
var ssh = new Rebex.Net.Ssh();
// initialize factory
SimpleSocketFactory factory = new SimpleSocketFactory();
factory.SocketConnecting += factory_SocketConnecting;
// use the factory
ssh.SetSocketFactory(factory);
// connect to the server
ssh.Connect(hostname);
' create SSH client instance
Dim ssh = New Rebex.Net.Ssh()
' initialize factory
Dim factory As New SimpleSocketFactory()
AddHandler factory.SocketConnecting, AddressOf factory_SocketConnecting
' use the factory
ssh.SetSocketFactory(factory)
' connect to the server
ssh.Connect(hostname)
Custom transport layer (ISocket/ISocketFactory) implementation
/// <summary>
/// Exposes SocketConnected event which is raised
/// when a socket successfully connects to a remote end.
/// </summary>
public class SimpleSocketFactory : ISocketFactory
{
/// <summary>
/// Occurs when a socket successfully connects to a remote end.
/// </summary>
public event EventHandler SocketConnecting;
// creates custom ISocket implementation
ISocket ISocketFactory.CreateSocket()
{
return new SimpleSocket(this);
}
// raises event
private void OnSocketConnecting()
{
EventHandler h = SocketConnecting;
if (h != null)
h(this, EventArgs.Empty);
}
// simple ISocket implementation
// (core functionality is taken from ProxySocket)
private class SimpleSocket : ProxySocket, ISocket
{
// creator object
private readonly SimpleSocketFactory _factory;
public SimpleSocket(SimpleSocketFactory factory)
{
_factory = factory;
}
// connects to a server and raises SocketConnected event
void ISocket.Connect(string serverName, int serverPort)
{
_factory.OnSocketConnecting();
base.Connect(serverName, serverPort);
}
// connects to a server and raises SocketConnected event
void ISocket.Connect(EndPoint endpoint)
{
_factory.OnSocketConnecting();
base.Connect(endpoint);
}
}
}
''' <summary>
''' Exposes SocketConnected event which is raised
''' when a socket successfully connects to a remote end.
''' </summary>
Public Class SimpleSocketFactory
Implements ISocketFactory
''' <summary>
''' Occurs when a socket successfully connects to a remote end.
''' </summary>
Public Event SocketConnecting As EventHandler
' creates custom ISocket implementation
Private Function ISocketFactory_CreateSocket() As ISocket Implements ISocketFactory.CreateSocket
Return New SimpleSocket(Me)
End Function
' raises event
Private Sub OnSocketConnecting()
RaiseEvent SocketConnecting(Me, EventArgs.Empty)
End Sub
' simple ISocket implementation
' (core functionality is taken from ProxySocket)
Private Class SimpleSocket
Inherits ProxySocket
Implements ISocket
' creator object
Private ReadOnly _factory As SimpleSocketFactory
Public Sub New(factory As SimpleSocketFactory)
_factory = factory
End Sub
' connects to a server and raises SocketConnected event
Private Sub ISocket_Connect(serverName As String, serverPort As Integer) Implements ISocket.Connect
_factory.OnSocketConnecting()
MyBase.Connect(serverName, serverPort)
End Sub
' connects to a server and raises SocketConnected event
Private Sub ISocket_Connect(endpoint As EndPoint) Implements ISocket.Connect
_factory.OnSocketConnecting()
MyBase.Connect(endpoint)
End Sub
End Class
End Class
Please note that custom communication layer and proxy support are mutually exclusive - it's not possible to use both at the same time.
Back to feature list...