BlockingSshClient

Blocking wrapper for SshClient for Java compatibility.

This class wraps the async SshClient with blocking calls using runBlocking. For Kotlin code, prefer using SshClient directly with coroutines.

Usage from Java:

BlockingSshClient client = new BlockingSshClient("example.com", 22, myHostKeyVerifier);
try {
client.connect();
client.authenticatePassword("user", "password");
SshSession session = client.openSession();
// ...
session.close();
client.disconnect();
} catch (SshException e) {
// handle connection or auth failure
}

With custom transport:

BlockingSshClient client = new BlockingSshClient(myTransportFactory, myHostKeyVerifier);

Constructors

Link copied to clipboard
constructor(host: String, port: Int = 22, hostKeyVerifier: HostKeyVerifier, clientVersion: String = "SSH-2.0-CBSSH_1.0")

Create a blocking SSH client for TCP connection.

constructor(config: SshClientConfig)

Create a blocking SSH client from configuration.

constructor(transportFactory: TransportFactory, hostKeyVerifier: HostKeyVerifier, clientVersion: String = "SSH-2.0-CBSSH_1.0")

Create a blocking SSH client with custom transport factory.

Properties

Link copied to clipboard
val disconnectedFlow: SharedFlow<Throwable?>

Emits when the connection drops unexpectedly.

Link copied to clipboard

Check if connected and authenticated.

Functions

Link copied to clipboard
fun authenticate(username: String, handler: AuthHandler)

Authenticate using the strategy-based AuthHandler flow.

Link copied to clipboard

Authenticate using keyboard-interactive authentication (RFC 4256).

Link copied to clipboard
fun authenticatePassword(username: String, password: String)

Authenticate using password authentication.

Link copied to clipboard
fun authenticatePublicKey(username: String, privateKeyData: ByteArray, passphrase: String? = null)
fun authenticatePublicKey(username: String, privateKeyData: String, passphrase: String? = null)

Authenticate using public key authentication (RFC 4252 ยง7).

Link copied to clipboard
fun connect()

Connect to the SSH server and perform key exchange.

Link copied to clipboard

Disconnect from the SSH server.

Link copied to clipboard

Start dynamic (SOCKS5) port forwarding.

fun dynamicPortForward(bindPort: Int, authenticator: Socks5Authenticator? = null): PortForwarder?

Start dynamic (SOCKS5) port forwarding bound to localhost.

Link copied to clipboard

Enable SSH agent forwarding with the provided agent.

Link copied to clipboard
fun forwardStream(readChannel: ByteReadChannel, writeChannel: ByteWriteChannel, remoteHost: String, remotePort: Int, originAddr: String = "127.0.0.1", originPort: Int = 0): StreamForwarder?

Forward Ktor byte channels through an SSH direct-tcpip channel.

Link copied to clipboard
fun localPortForward(bindAddress: InetSocketAddress, remoteHost: String, remotePort: Int): PortForwarder?

Start local port forwarding.

fun localPortForward(bindPort: Int, remoteHost: String, remotePort: Int): PortForwarder?

Start local port forwarding bound to localhost.

Link copied to clipboard
fun openDirectTcpipTransport(remoteHost: String, remotePort: Int, originAddr: String = "127.0.0.1", originPort: Int = 0): TransportFactory?

Create a org.connectbot.sshlib.transport.TransportFactory that tunnels through this SSH connection.

Link copied to clipboard

Open a session channel (RFC 4254 section 6.1).

Link copied to clipboard

Open an SFTP session for file transfer (blocking wrapper).

Link copied to clipboard

Send an SSH ping to the server and return the result.

Link copied to clipboard
fun remotePortForward(remoteBindAddress: String, remoteBindPort: Int, localHost: String, localPort: Int): PortForwarder?

Start remote port forwarding.