Loading...

Using HTTP or SOCKS Proxies

You can use an HTTP or SOCKS 4/5 proxy to establish client connections with Maverick Synergy.

This requires that you create the SshClientContext and pass this to the SshClient constructor.

HTTP

For a simple anonymous HTTP Proxy

SshClientContext ctx = new SshClientContext();
ctx.enableHTTPProxy("localhost", 9999);Code language: JavaScript (javascript)

Then, establish the connection with your SshClient, passing the SshClientContext to the constructor.

try (SshClient ssh = SshClientBuilder.create()
		.withHostname("localhost")
		.withPort(2222)
		.withUsername("root")
		.withPassword("xxxx")
		.withSshContext(ctx)
		.build()) {
}Code language: JavaScript (javascript)

If required, you can pass credentials when setting up the proxy.

ctx.enableHTTPProxy("localhost", 9999, "lee", "password123?");Code language: JavaScript (javascript)

SOCKS

There are options for SOCKS 4 and SOCKS 5 Proxies. Again as outlined above this is a configuration on the SshClientContext.

SOCKS 4 does not support authentication.

ctx.enableSocks4Proxy("localhost", 8889, "lee");Code language: JavaScript (javascript)

Now, connect with your SshClient, passing the SshClientContext to the constructor.

try (SshClient ssh = SshClientBuilder.create()
		.withHostname("localhost")
		.withPort(2222)
		.withUsername("root")
		.withPassword("xxxx")
		.withSshContext(ctx)
		.build()) {
}Code language: JavaScript (javascript)

SOCKS 5 supports authentication; you can pass an empty or null string if you don’t need to use authentication. The boolean flag on the end determines if the API tries to resolve the hostname locally (true) or remotely (false).

ctx.enableSocks5Proxy("localhost", 8889, "lee", "", false);Code language: JavaScript (javascript)
To top