SSHClient class

Uses specified credentials to create a connection to a host.

Using a password:

var client = new SSHClient(
  host: "my.sshtest",
  port: 22,
  username: "sha",
  passwordOrKey: "Password01.",
);```

Using a key:
```dart
var client = new SSHClient(
  host: "my.sshtest",
  port: 22,
  username: "sha",
  passwordOrKey: {
    "privateKey": """-----BEGIN RSA PRIVATE KEY-----
    ......
-----END RSA PRIVATE KEY-----""",
    "passphrase": "passphrase-for-key",
  },
);

Recent versions of OpenSSH introduce a proprietary key format that is not supported by most other software, including this one, you must convert it to a PEM-format RSA key using the puttygen tool. On Windows this is a graphical tool. On the Mac, install it per these instructions. On Linux install your distribution's putty or puttygen packages.

  • Temporarily remove the passphrase from the original key (enter blank password as the new password) ssh-keygen -p -f id_rsa
  • convert to RSA PEM format puttygen id_rsa -O private-openssh -o id_rsa_unencrypted
  • re-apply the passphrase to the original key ssh-keygen -p -f id_rsa
  • apply a passphrase to the converted key: puttygen id_rsa_unencrypted -P -O private-openssh -o id_rsa_flutter
  • remove the unencrypted version: rm id_rsa_unencrypted

Constructors

SSHClient({required String host, required int port, required String username, required dynamic passwordOrKey})

Properties

downloadCallback Callback?
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
host String
getter/setter pair
id String?
getter/setter pair
passwordOrKey ↔ dynamic
getter/setter pair
port int
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
shellCallback Callback?
getter/setter pair
stateSubscription StreamSubscription
getter/setter pair
uploadCallback Callback?
getter/setter pair
username String
getter/setter pair

Methods

closeShell() Future
Closes the shell.
connect() Future<String?>
Attempts to connect to the host using specified credentials. Returns the result of the connection attempt.
connectSFTP() Future<String?>
Connects to an SFTP server.
disconnect() → dynamic
Closes the SSH client connection.
disconnectSFTP() Future
Closes the SFTP connection.
execute(String cmd) Future<String?>
Sends a non-interactive ssh command. Returns the output of the command.
getHostFingerprint() Future<String>
Gets the fingerprint of the remote host.
getRemoteBanner() Future<String>
Gets the banner of the remote host.
isConnected() Future<bool>
Checks to see if the SSH client is currently connected.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
portForwardL(int rport, int lport, String rhost) Future<String?>
Forward a port from the remote to the local host.
sftpCancelDownload() Future
Cancels an ongoing download using SFTP.
sftpCancelUpload() Future
Cancels an ongoing upload using SFTP.
sftpDownload({required String path, required String toPath, Callback? callback}) Future<String?>
Downloads the specified file using SFTP.
sftpLs([String path = '.']) Future<List?>
Performs a directory listing using SFTP. Defaults to the current directory.
sftpMkdir(String path) Future<String?>
Creates a new directory in the current directory using SFTP.
sftpRename({required String oldPath, required String newPath}) Future<String?>
Renames a directory using SFTP.
sftpRm(String path) Future<String?>
Removes the specified file using SFTP.
sftpRmdir(String path) Future<String?>
Removes the specified directory using SFTP.
sftpUpload({required String path, required String toPath, Callback? callback}) Future<String?>
Uploads a file using SFTP.
startShell({String ptyType = "vanilla", Callback? callback}) Future<String?>
Starts an SSH shell. Use the specified callback to receive shell output.
toString() String
A string representation of this object.
inherited
writeToShell(String cmd) Future<String?>
Sends a string to the shell.

Operators

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