パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v2.2.3

ssh2

Flutter用のSSHおよびSFTPクライアント。iOSライブラリNMSSHとAndroidライブラリJSchをラップしています。

AndroidiOS
30日間ダウンロード
60
いいね数
32
Pub ポイント
130

パッケージをインストール

flutter pub add ssh2

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

ネイティブライブラリ NMSSH(iOS)およびJSch(Android)をラップすることで、AndroidおよびiOSでSSHおよびSFTP接続を可能にするFlutterパッケージです。セキュアなリモートサーバーへのアクセスとファイル転送を可能にし、サーバーとの暗号化された通信が必要なアプリケーションに最適です。このパッケージは、接続の確立、コマンドの実行、SFTP経由でのファイル管理を行うためのシンプルなインターフェースを提供します。リモート設定、デプロイメント、またはデータ同期などのシナリオにおいて特に有用です。開発者はプラットフォーム固有の最適化の利点を得ながらも、クロスプラットフォームの一貫性を維持できます。

用途

  • リモートサーバー管理
  • SFTP を通じた安全なファイル転送
  • 自動デプロイワークフロー
  • サーバー構成の自動化
  • リモートコマンド実行
  • リモートシステムとのデータ同期

主な機能

  • クロスプラットフォーム対応のSSHおよびSFTPサポート
  • ネイティブライブラリの統合(NMSSH、JSch)
  • セキュアな暗号化接続
  • リモートサーバー上のコマンド実行
  • ファイル転送機能
  • プラットフォーム固有のパフォーマンス最適化

適している対象

  • リモート管理ツールを開発する開発者
  • セキュアなサーバーへのアクセスが必要なアプリ
  • CI/CD 統合機能
  • IoTデバイス構成アプリ
  • セキュアなファイル処理を必要とするアプリケーション

注意事項

  • iOS および Android のネイティブ依存関係が必要です
  • AndroidおよびiOSプラットフォームに限定
  • ファイアウォールまたは鍵認証のための追加設定が必要になる場合があります
  • Webやデスクトップターゲットには適していません
  • SSHキーおよび証明書の取り扱いにおける潜在的な複雑さ

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

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.

カテゴリー

依存関係

依存関係一覧 1 件

ソースリポジトリ

このパッケージを使用しているプロジェクト