ssh 0.0.5

  • Readme
  • Changelog
  • Example
  • Installing
  • 87

ssh #

SSH and SFTP client for Flutter. Wraps iOS library NMSSH and Android library JSch.

Installation #

Add ssh as a dependency in your pubspec.yaml file.

Usage #

Create a client using password authentication #

import 'package:ssh/ssh.dart';

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

Create a client using public key authentication #

import 'package:ssh/ssh.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",
  },
);

OpenSSH keys #

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

Connect client #

await client.connect();

Close client #

await client.disconnect();

Execute SSH command #

var result = await client.execute("ps");

Shell #

Start shell: #

  • Supported ptyType: vanilla, vt100, vt102, vt220, ansi, xterm
var result = await client.startShell(
  ptyType: "xterm", // defaults to vanilla
  callback: (dynamic res) {
    print(res);     // read from shell
  }
);

Write to shell: #

await client.writeToShell("ls\n");

Close shell: #

await client.closeShell();

SFTP #

Connect SFTP: #

await client.connectSFTP();

List directory: #

var array = await client.sftpLs("/home"); // defaults to .

Create directory: #

await client.sftpMkdir("testdir");

Rename file or directory: #

await client.sftpRename(
  oldPath: "testfile",
  newPath: "newtestfile",
);

Remove directory: #

await client.sftpRmdir("testdir");

Remove file: #

await client.sftpRm("testfile");

Download file: #

var filePath = await client.sftpDownload(
  path: "testfile",
  toPath: tempPath,
  callback: (progress) {
    print(progress); // read download progress
  },
);

// Cancel download:
await client.sftpCancelDownload();

Upload file: #

await client.sftpUpload(
  path: filePath,
  toPath: ".",
  callback: (progress) {
    print(progress); // read upload progress
  },
);

// Cancel upload:
await client.sftpCancelUpload();

Close SFTP: #

await client.disconnectSFTP();

Demo #

Refer to the example.

0.0.5 #

  • Fixed download exception on Android due to this issue.

0.0.4 #

  • Changed disconnect() method to sync.
  • Fixed Android crash issue "Methods marked with @UiThread must be executed on the main thread.".

0.0.3 #

  • Fixed invokeMethod missing indirection.
  • Add note about OpenSSH keys, add passphrase to key example.

0.0.2 #

  • Check if client is null before getting session in Android.

0.0.1 #

  • Initial release.

example/README.md

ssh_example #

Demonstrates how to use the ssh plugin.

Install #

flutter packages get

Run #

flutter run

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  ssh: ^0.0.5

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:ssh/ssh.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
83
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
87
Learn more about scoring.

We analyzed this package on Dec 13, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.1+4
  • Flutter: 1.12.13+hotfix.4

Health issues and suggestions

Document public APIs. (-1 points)

40 out of 40 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (uuid).

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
flutter 0.0.0
uuid ^1.0.3 1.0.3 2.0.4
Transitive dependencies
charcode 1.1.2
collection 1.14.11 1.14.12
convert 2.1.1
crypto 2.1.4
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8