SSHClient class

Constructors

SSHClient(SSHSocket socket, {required String username, SSHPrintHandler? printDebug, SSHPrintHandler? printTrace, SSHAlgorithms algorithms = const SSHAlgorithms(), SSHHostkeyVerifyHandler? onVerifyHostKey, List<SSHKeyPair>? identities, SSHPasswordRequestHandler? onPasswordRequest, SSHChangePasswordRequestHandler? onChangePasswordRequest, SSHUserInfoRequestHandler? onUserInfoRequest, SSHUserauthBannerHandler? onUserauthBanner, SSHAuthenticatedHandler? onAuthenticated, Duration? keepAliveInterval = const Duration(seconds: 10)})

Properties

algorithms SSHAlgorithms
Crypto algorithms available for the client.
final
authenticated Future<void>
A Future that completes when the client has authenticated, or completes with an error if the client could not authenticate.
no setter
done Future<void>
Function called when additional host keys are received. This is an OpenSSH extension. May not be called if the server does not support the extension. A Future that completes when the transport is closed, or when an error occurs. After this Future completes, isClosed will be true and no more data can be sent or received.
no setter
hashCode int
The hash code for this object.
no setterinherited
identities List<SSHKeyPair>?
List of key pairs to use for authentication. Set this field to enable authentication with public key.
final
isClosed bool
true if the connection is closed normally or due to an error.
no setter
keepAliveInterval Duration?
The interval at which to send a keep-alive message through the ping method. Set this to null to disable automatic keep-alive messages.
final
onAuthenticated SSHAuthenticatedHandler?
A Future that completes normally when the client is connected to the Function called when authentication is complete.
final
onChangePasswordRequest SSHChangePasswordRequestHandler?
Set this field to enable setting new passwords when the server requests changing password when using the 'password' authentication method. Return null to skip to the next available authentication method.
final
onPasswordRequest SSHPasswordRequestHandler?
Set this field to enable the 'password' authentication method. Return null to skip to the next available authentication method.
final
onUserauthBanner SSHUserauthBannerHandler?
The SSH server may send banner message at any time before authentication is successful. Set this field to receive the banner message.
final
onUserInfoRequest SSHUserInfoRequestHandler?
Set this field to enable the 'keyboard-interactive' authentication method. This may be called multiple times to request additional prompts. Return null to skip to the next available authentication method.
final
onVerifyHostKey SSHHostkeyVerifyHandler?
Function called when the first host key is received. Return true to accept the host key, false to reject it and close the connection. If this is null, the host key is accepted automatically.
final
printDebug SSHPrintHandler?
Function invoked with debug messages.
final
printTrace SSHPrintHandler?
Function invoked with network traffic messages.
final
remoteVersion String?
Identification string sent by the other side. For example, "SSH-2.0-OpenSSH_7.4p1". May be null if the handshake has not yet completed.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
socket SSHSocket
final
username String
The username to authenticate as.
final

Methods

cancelForwardRemote(SSHRemoteForward forward) Future<bool>
Cancel a previous request to forward connections to a port on the other side. Returns true if successful, false otherwise. See also: forwardRemote.
close() → void
Shutdown the entire SSH connection. Sessions and channels will also be closed immediately.
execute(String command, {SSHPtyConfig? pty, Map<String, String>? environment}) Future<SSHSession>
Execute command on the remote side. Returns a SSHChannel that can be used to read and write to the remote side.
forwardLocal(String remoteHost, int remotePort, {String localHost = 'localhost', int localPort = 0}) Future<SSHForwardChannel>
Forward connections to a localHost:localPort to remoteHost:remotePort localHost and localPort are only required by the protocol and do not need to be specified in most cases.
forwardRemote({String? host, int? port, SSHRemoteConnectionFilter? filter}) Future<SSHRemoteForward?>
Request connections to a port on the other side be forwarded to the local side. Set host to null to listen on all interfaces, "0.0.0.0" to listen on all IPv4 interfaces, "::" to listen on all IPv6 interfaces, and "localhost" to listen on the loopback interface on all protocols. Set port to null to listen on a random port.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
ping() Future<void>
Send a empty message to the server to keep the connection alive.
run(String command, {bool runInPty = false, bool stdout = true, bool stderr = true, Map<String, String>? environment}) Future<Uint8List>
Execute command on the remote side non-interactively. Returns a Future<String?> that completes with the output of the command. This is a convenience method over execute. If stdout is false, the standard output of the command will be ignored. If stderr is false, the standard error of the command will be ignored.
sftp() Future<SftpClient>
shell({SSHPtyConfig? pty = const SSHPtyConfig(), Map<String, String>? environment}) Future<SSHSession>
subsystem(String subsystem) Future<void>
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited