搜尋套件、儲存庫與 APP 分類

套件詳情v0.0.7

ssh

適用於 Flutter 的 SSH 與 SFTP 客戶端。封裝了 iOS 庫 NMSSH 與 Android 庫 JSch。

近 30 天下載
83
喜歡數
42
Pub 分數
35

安裝套件

flutter pub add ssh

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個 Flutter 套件,透過封裝原生程式庫(iOS 使用 NMSSH,Android 使用 JSch)提供 SSH 與 SFTP 客戶端功能。它讓 Flutter 應用能夠實現安全的遠端連線與檔案傳輸,支援透過密碼或金鑰進行驗證。此套件專為需要跨平台網路作業並使用安全協定的開發者設計,簡化將基於 SSH 的工作流程整合至行動應用的過程,無需深入特定平台知識。

適用情境

  • 遠端伺服器管理
  • 透過 SFTP 安全傳輸檔案
  • 自動化部署腳本
  • 安全設備配置
  • 遠端除錯
  • 系統管理任務

主要特色

  • 跨平台 SSH/SFTP 支援
  • 密碼和金鑰認證
  • 與 iOS NMSSH 和 Android JSch 的整合
  • 用於連接和檔案操作的簡單 API
  • 安全加密通訊

適合對象

  • 開發人員建構管理工具
  • 需要遠端存取的行動應用程式
  • 移動應用中的CI/CD整合
  • 網路自動化專案
  • 處理安全資料交換的應用程式

使用建議

  • iOS 和 Android 需要原生庫設定
  • 僅限iOS和Android平台
  • 身份驗證憑據必須安全處理
  • 低端設備上可能有潛在的效能開銷
  • 沒有用於SSH會話的內建UI元件

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

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.

Known issue

  • Platform exception in release mode for Android:

    PlatformException(connection_failure, java.lang.ClassNotFoundException: com.jcraft.jsch.jce.Random, null)
    

    There are 2 workarounds:

    • Disable shrink:

      flutter build apk --no-shrink

    • Configure proguard-rules. Refer to this comment for details.

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.

所屬分類

依賴

依賴清單 2 項

原始碼儲存庫

使用此套件的專案