Search packages, repositories and app categories

Package detailsv2.2.3

ssh2

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

AndroidiOS
30-day downloads
60
Likes
32
Pub points
130

Install package

flutter pub add ssh2

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

A Flutter package that enables SSH and SFTP connectivity on Android and iOS by wrapping native libraries NMSSH (iOS) and JSch (Android). It allows secure remote server access and file transfers, making it ideal for applications requiring encrypted communication with servers. The package provides a straightforward interface to establish connections, execute commands, and manage files over SFTP. It is particularly useful in scenarios involving remote configuration, deployment, or data synchronization. Developers benefit from platform-specific optimizations while maintaining cross-platform consistency.

Use cases

  • Remote server management
  • Secure file transfer via SFTP
  • Automated deployment workflows
  • Server configuration automation
  • Remote command execution
  • Data synchronization with remote systems

Key features

  • Cross-platform SSH and SFTP support
  • Native library integration (NMSSH, JSch)
  • Secure encrypted connections
  • Command execution on remote servers
  • File transfer capabilities
  • Platform-specific performance optimization

Suitable for

  • Developers building remote administration tools
  • Apps needing secure server access
  • CI/CD integration features
  • IoT device configuration apps
  • Applications requiring secure file handling

Considerations

  • Requires native dependencies on iOS and Android
  • Limited to Android and iOS platforms
  • May require additional setup for firewall or key authentication
  • Not suitable for web or desktop targets
  • Potential complexity in handling SSH keys and certificates

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

ssh2

SSH and SFTP client for Flutter. Wraps iOS library NMSSH and Android library JSch. This is a fork of flutter_ssh: https://github.com/shaqian/flutter_ssh

Wraps iOS library NMSSH and Android library JSch.

Installation

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

Known issue

  • Older Gradle versions are not supported due to incompatibilities with the newer JSch dependency. This release was tested with Gradle version 7.0.2.

Usage

Create a client using password authentication
import 'package:ssh2/ssh2.dart';

var client = new SSHClient(
  host: "my.sshtest",
  port: 22,
  username: "sha",
  passwordOrKey: "Password01.",
);
Create a client using public key authentication
import 'package:ssh2/ssh2.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");
Get the fingerprint of the remote host
var result = await client.getHostFingerprint();
Get the banner of the remote host
var result = await client.getBanner();
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.

Categories

Dependencies

Dependency list 1 items

Source repository

Projects using this package