v2.2.3
ssh2
适用于 Flutter 的 SSH 和 SFTP 客户端。封装了 iOS 库 NMSSH 和 Android 库 JSch。
32喜欢 67近 30 天下载130Pub 分数
AndroidiOS
适用于 Flutter 的 SSH 和 SFTP 客户端
{"sdk":"flutter"}^3.0.4以下为英文项目原文快照,最新内容请访问 GitHub。
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.
Add ssh2 as a dependency in your pubspec.yaml file.
import 'package:ssh2/ssh2.dart';
var client = new SSHClient(
host: "my.sshtest",
port: 22,
username: "sha",
passwordOrKey: "Password01.",
);
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",
},
);
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.
ssh-keygen -p -f id_rsaputtygen id_rsa -O private-openssh -o id_rsa_unencryptedssh-keygen -p -f id_rsaputtygen id_rsa_unencrypted -P -O private-openssh -o id_rsa_flutterrm id_rsa_unencryptedawait client.connect();
await client.disconnect();
var result = await client.execute("ps");
var result = await client.getHostFingerprint();
var result = await client.getBanner();
var result = await client.startShell(
ptyType: "xterm", // defaults to vanilla
callback: (dynamic res) {
print(res); // read from shell
}
);
await client.writeToShell("ls\n");
await client.closeShell();
await client.connectSFTP();
var array = await client.sftpLs("/home"); // defaults to .
await client.sftpMkdir("testdir");
await client.sftpRename(
oldPath: "testfile",
newPath: "newtestfile",
);
await client.sftpRmdir("testdir");
await client.sftpRm("testfile");
var filePath = await client.sftpDownload(
path: "testfile",
toPath: tempPath,
callback: (progress) {
print(progress); // read download progress
},
);
// Cancel download:
await client.sftpCancelDownload();
await client.sftpUpload(
path: filePath,
toPath: ".",
callback: (progress) {
print(progress); // read upload progress
},
);
// Cancel upload:
await client.sftpCancelUpload();
await client.disconnectSFTP();
Refer to the example.