Ssh Client
High-level async SSH client API.
This is the main entry point for establishing SSH connections. All methods are suspend functions for use with Kotlin coroutines.
Usage with TCP (default):
val client = SshClient("example.com", hostKeyVerifier = myVerifier)
if (client.connect() is ConnectResult.Success) {
if (client.authenticatePassword("user", "password") is AuthResult.Success) {
val session = client.openSession()
session?.requestPty()
session?.requestShell()
// read/write
session?.close()
}
client.disconnect()
}Usage with custom transport:
val config = SshClientConfig {
transportFactory = MyCustomTransportFactory()
}
val client = SshClient(config)
client.connect()
// ...For blocking Java compatibility, use org.connectbot.sshlib.blocking.BlockingSshClient.
Properties
Functions
Authenticate using the strategy-based AuthHandler flow.
Authenticate using keyboard-interactive authentication (RFC 4256).
Authenticate using password authentication.
Authenticate using public key authentication (RFC 4252 ยง7).
Connect to the SSH server and perform key exchange.
Disconnect from the SSH server.
Start dynamic (SOCKS5) port forwarding.
Start dynamic (SOCKS5) port forwarding bound to localhost.
Enable SSH agent forwarding with the provided agent.
Forward a pair of streams through an SSH direct-tcpip channel.
Check if the provided private key data is encrypted and requires a passphrase.
Start local port forwarding (RFC 4254 section 7.2).
Start local port forwarding bound to localhost.
Create a TransportFactory that tunnels through this SSH connection.
Open a session channel (RFC 4254 section 6.1).
Open an SFTP session for file transfer.
Send an SSH ping to the server and return the round-trip time.
Start remote port forwarding (RFC 4254 section 7.1).