패키지, 저장소 및 앱 카테고리 검색

패키지 상세v2.2.3

ssh2

Flutter용 SSH 및 SFTP 클라이언트입니다. iOS 라이브러리 NMSSH와 Android 라이브러리 JSch를 래핑합니다.

AndroidiOS
30일 다운로드
60
좋아요
32
Pub 점수
130

패키지 설치

flutter pub add ssh2

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

네이티브 라이브러리 NMSSH(아이오스)와 JSch(안드로이드)를 래핑하여 안드로이드 및 iOS에서 SSH 및 SFTP 연결을 가능하게 하는 플러터 패키지입니다. 안전한 원격 서버 접근과 파일 전송을 가능하게 하며, 서버와의 암호화된 통신이 필요한 애플리케이션에 이상적입니다. 이 패키지는 연결 설정, 명령 실행, SFTP를 통한 파일 관리를 위한 간단한 인터페이스를 제공합니다. 원격 구성, 배포 또는 데이터 동기화와 같은 상황에서 특히 유용합니다. 개발자는 플랫폼별 최적화의 이점을 누리면서도 크로스플랫폼 일관성을 유지할 수 있습니다.

사용 사례

  • 원격 서버 관리
  • SFTP를 통한 안전한 파일 전송
  • 자동화된 배포 워크플로우
  • 서버 구성 자동화
  • 원격 명령 실행
  • 원격 시스템과의 데이터 동기화

주요 기능

  • 다중 플랫폼 SSH 및 SFTP 지원
  • 네이티브 라이브러리 통합 (NMSSH, JSch)
  • 보안 암호화 연결
  • 원격 서버에서 명령 실행
  • 파일 전송 기능
  • 플랫폼별 성능 최적화

적합한 대상

  • 원격 관리 도구를 개발하는 개발자
  • 안전한 서버 액세스가 필요한 앱
  • CI/CD 통합 기능
  • 사물인터넷 장치 구성 앱
  • 안전한 파일 처리가 필요한 응용 프로그램

고려 사항

  • iOS 및 안드로이드의 네이티브 종속성이 필요합니다
  • Android 및 iOS 플랫폼에 한정
  • 방화벽 또는 키 인증을 위해 추가 설정이 필요할 수 있습니다
  • 웹 또는 데스크톱 대상에 적합하지 않습니다
  • 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 개

소스 저장소

이 패키지를 사용하는 프로젝트