# @dylankenneally/react-native-ssh-sftp 中文文档

规范地址：https://npmcn.com/package/%40dylankenneally/react-native-ssh-sftp/

版本：1\.11\.0
npm 元数据更新时间：2026-07-04T11:33:21.256Z
中文译文更新时间：2026-11-13T02:09:55.087Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40dylankenneally/react-native-ssh-sftp
原文对照：https://npmcn.com/package/%40dylankenneally/react-native-ssh-sftp/?lang=original
项目主页：https://github.com/dylankenneally/react-native-ssh-sftp#readme
源码仓库：https://github.com/dylankenneally/react-native-ssh-sftp

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：124 kB，17 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=22\.0\.0
- 运行依赖：0 个
- peer 依赖：react-native \*
- 首次发布：2024-01-17T05:51:15.498Z
- 最新版本发布：2026-07-04T11:33:20.998Z
- 近 30 天下载量：40507（2026-10-13 至 2026-11-11，npm 官方下载统计）
- 已发布版本数：24（近 12 个月 11 个）

## 中文简介

SSH 和 SFTP 客户端库

## 安装

```sh
npm install @dylankenneally/react-native-ssh-sftp
```

也可以使用：`pnpm add @dylankenneally/react-native-ssh-sftp`、`yarn add @dylankenneally/react-native-ssh-sftp`、`bun add @dylankenneally/react-native-ssh-sftp`

## README

# SSH 和 SFTP 客户端库

SSH和SFTP客户端库用于在iOS和Android上的React Introduct.

[![Compile package](https://github.com/dylankenneally/react-native-ssh-sftp/actions/workflows/compile.yml/badge.svg)](https://github.com/dylankenneally/react-native-ssh-sftp/actions/workflows/compile.yml) [![Publish package to npmjs.com](https://github.com/dylankenneally/react-native-ssh-sftp/actions/workflows/publish.yml/badge.svg)](https://github.com/dylankenneally/react-native-ssh-sftp/actions/workflows/publish.yml) [![View documentation](https://img.shields.io/badge/View-documentation-blue)](https://dylankenneally-react-native-ssh-sftp-96.mintlify.app/)

## 完整文档

一整套 [文件可在Mintlify上查阅](https://dylankenneally-react-native-ssh-sftp-96.mintlify.app/),包括:

1.  安装
2.  快速启动指南
3.  API 参考
4.  核心概念
5.  指南

以下为快速安装和使用指南以起起跑. 这个 [完整文档](https://dylankenneally-react-native-ssh-sftp-96.mintlify.app/) 现建议除下文外,再作补充.

> \[尖叫声\] **主机密钥验证未执行 .** 此库不会校验或锁定远程服务器的主机密钥( 在 Android 上) `StrictHostKeyChecking` 已禁用,在iOS上,主机密钥不检查),所以连接容易被中层人攻击. 在解决之前, 只能通过您信任的网络连接 。 见 [安全指南](https://dylankenneally-react-native-ssh-sftp-96.mintlify.app/guides/security) 详细情况.

## 安装

```bash
npm install @dylankenneally/react-native-ssh-sftp
```

### iOS系统

更新您的 `Podfile` 用于使用 [亚拿0的叉子](https://github.com/aanah0/NMSSH) 联 合 国 [NSSSH (英语)](https://github.com/NMSSH/NMSSH)。请注意,我们使用forked版本给我们一个所需的后期版本libsh。  `Podfile` 位于您的 React 原生项目 : `./ios/Podfile`。 。 。 .

```ruby
target '[your project's name]' do
  pod 'NMSSH', :git => 'https://github.com/aanah0/NMSSH.git' # <-- add this line
  # ... rest of your target details ...
end
```

然后跑开 `pod install` 在你身边 `./ios` 目录.

```bash
cd ios
pod install
cd -
```

> \[TIP\] 添加一个 `postinstall` 脚本到您的 `package.json` 要运行的文件 `pod install` 之后 `npm install` 这是一个好主意。 这个 [`pod-install`](https://www.npmjs.com/package/pod-install) 软件包是这样做的好方法.
> 
> ```json
> {
>   "scripts": {
>     "postinstall": "npx pod-install",
>   }
> }
> ```

#### 在 iOS 有 OpenSSL 问题吗 ?

使用时 [翻转](https://fbflipper.com/) 要调试您的应用程序, 它将会包含 OpenSSL 的副本 。 这可能会与NMSSH使用的OpenSSL版本产生问题. 您可以通过删除/ 注释来禁用翻转器 `flipper_configuration => flipper_config,` 线条 `Podfile`。 。 。 .

### 机器人

Android不需要额外的步骤.

### 链接

这个项目经过了更新,可以使用React Industrial v84(最晚在撰写时为2026年2月)——这意味着不需要手动连接.

## 使用量

所有同步运行的函数, 此时我们必须等待结果 返回如果出错时可以拒绝的承诺 .

> \[注\] 在iOS上,此软件包目前不支持模拟器,您需要将您的应用程序运行在物理设备上. 如果你想知道更多关于这个,你看 [这个问题](https://github.com/dylankenneally/react-native-ssh-sftp/issues/20)我欢迎公关解决这件事.

### 使用密码认证创建客户端

```javascript
import SSHClient from '@dylankenneally/react-native-ssh-sftp';

SSHClient.connectWithPassword(
  "10.0.0.10",
  22,
  "user",
  "password"
).then(client => {/*...*/});
```

### 使用公钥认证创建客户端

```javascript
import SSHClient from 'react-native-ssh-sftp';

SSHClient.connectWithKey(
  "10.0.0.10",
  22,
  "user",
  privateKey="-----BEGIN RSA...",
  passphrase
).then(client => {/*...*/});
```

#### 公钥认证也得到支持

```plaintext
{privateKey: '-----BEGIN RSA......'}
{privateKey: '-----BEGIN RSA......', publicKey: 'ssh-rsa AAAAB3NzaC1yc2EA......'}
{privateKey: '-----BEGIN RSA......', publicKey: 'ssh-rsa AAAAB3NzaC1yc2EA......', passphrase: 'Password'}
```

### 关闭客户端

```javascript
client.disconnect();
```

### 执行 SSH 命令

```javascript
const command = 'ls -l';
client.execute(command)
  .then(output => console.warn(output));
```

### 贝壳

#### 启动外壳

-   支持的 ptyType: 香草, vt100, vt102, vt220, ansi, xterm

```javascript
const ptyType = 'vanilla';
client.startShell(ptyType)
  .then(() => {/*...*/});
```

#### 从 shell 读取

```javascript
client.on('Shell', (event) => {
  if (event)
    console.warn(event);
});
```

#### 写入到外壳

```javascript
const str = 'ls -l\n';
client.writeToShell(str)
  .then(() => {/*...*/});
```

#### 关闭外壳

```javascript
client.closeShell();
```

### SFTP 系统

#### 连接 SFTP

```javascript
client.connectSFTP()
  .then(() => {/*...*/});
```

#### 列表目录

```javascript
const path = '.';
client.sftpLs(path)
  .then(response => console.warn(response));
```

#### 创建目录

```javascript
client.sftpMkdir('dirName')
  .then(() => {/*...*/});
```

#### 重命名文件或目录

```javascript
client.sftpRename('oldName', 'newName')
  .then(() => {/*...*/});
```

#### 删除目录

```javascript
client.sftpRmdir('dirName')
  .then(() => {/*...*/});
```

#### 删除文件

```javascript
client.sftpRm('fileName')
  .then(() => {/*...*/});
```

#### 下载文件

```javascript
client.sftpDownload('[path-to-remote-file]', '[path-to-local-directory]')
  .then(downloadedFilePath => {
    console.warn(downloadedFilePath);
  });

// Download progress (setup before call)
client.on('DownloadProgress', (event) => {
  console.warn(event);
});

// Cancel download
client.sftpCancelDownload();
```

#### 上传文件

```javascript
client.sftpUpload('[path-to-local-file]', '[path-to-remote-directory]')
  .then(() => {/*...*/});

// Upload progress (setup before call)
client.on('UploadProgress', (event) => {
  console.warn(event);
});

// Cancel upload
client.sftpCancelUpload();
```

#### 关闭 SFTP

```javascript
client.disconnectSFTP();
```

## 示例应用程序

您可以为此库的用法找到一个非常简单的例子应用程序 [这里](https://github.com/dylankenneally/react-native-ssh-sftp-example)。 。 。 .

## 贷项

这个软件包包包了以下库,提供了实际的SSH/SFTP功能:

-   [NSSSH (英语)](https://github.com/aanah0/NMSSH) 为iOS服务
-   [约施](http://www.jcraft.com/jsch/) 用于Android([从马蒂亚斯·维德曼叉](https://github.com/mwiede/jsch)(中文(简体) )

这个包裹是埃马纽埃尔·纳蒂维达德的叉子 [反应-内生- ssh- sftp](https://github.com/enatividad/react-native-ssh-sftp) 软件包。 分叉链从那里取出如下:

1.  [加布里埃尔·保罗·"克莉·菲"·里斯特鲁奇](https://github.com/KeeeX/react-native-ssh-sftp)
2.  [比绍伊·米克海尔](https://github.com/MrBmikhael/react-native-ssh-sftp)
3.  [Q沙](https://github.com/shaqian/react-native-ssh-sftp)

## 常见问题

### @dylankenneally/react-native-ssh-sftp 是什么？

SSH 和 SFTP 客户端库

### 如何安装 @dylankenneally/react-native-ssh-sftp？

在项目目录运行 npm install @dylankenneally/react-native-ssh-sftp，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：react-native（\*）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @dylankenneally/react-native-ssh-sftp 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @dylankenneally/react-native-ssh-sftp 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @dylankenneally/react-native-ssh-sftp 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>=22\.0\.0。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @dylankenneally/react-native-ssh-sftp 可以商用吗？

@dylankenneally/react-native-ssh-sftp 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @dylankenneally/react-native-ssh-sftp 的下载量有多少？

根据 npm 官方下载统计，@dylankenneally/react-native-ssh-sftp 在 2026/10/13 – 2026/11/11 这 30 天内被下载 40,507 次，日均约 1,350 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @dylankenneally/react-native-ssh-sftp 还在维护吗？

最新版本 1\.11\.0 发布于 2026/07/04（4 个月前）；至今共发布 24 个版本，其中过去 12 个月发布了 11 个；首次发布于 2024/01/17。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

