@dylankenneally/react-native-ssh-sftp

中文文档
1.11.0发布于 2026/07/04MITTypeScriptCommonJS零依赖构建来源已验证近 30 天下载 4.1万

SSH and SFTP client library for React Native

原始使用文档
文档目录14 节
  1. Full documentation
  2. Installation
  3. iOS
  4. Android
  5. Linking
  6. Usage
  7. Create a client using password authentication
  8. Create a client using public key authentication
  9. Close client
  10. Execute SSH command
  11. Shell
  12. SFTP
  13. Example app
  14. Credits

SSH and SFTP client library for React Native

SSH and SFTP client library for React Native on iOS and Android.

Compile package Publish package to npmjs.com View documentation

Full documentation

A full set of documentation is available on Mintlify, which includes:

  1. Installation
  2. Quick start guide
  3. API reference
  4. Core concepts
  5. Guides

Below is a quick installation and usage guide to get up and running. The full documentation is recommended in addition to the below.

[!WARNING] Host key verification is not performed. This library does not verify or pin the remote server's host key (on Android StrictHostKeyChecking is disabled, and on iOS the host key is not checked), so connections are susceptible to man-in-the-middle attacks. Until this is addressed, only connect over networks you trust. See the security guide for details.

Installation

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

iOS

Update your Podfile to use the aanah0's fork of NMSSH. Note that we use the forked version to give us a required later version of libssh. Your Podfile is located in your React Native project at ./ios/Podfile.

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

And then run pod install in your ./ios directory.

cd ios
pod install
cd -

[!TIP] Adding a postinstall script to your package.json file to run pod install after npm install is a good idea. The pod-install package is a good way to do this.

{
  "scripts": {
    "postinstall": "npx pod-install",
  }
}

Having OpenSSL issues on iOS?

If you are using Flipper to debug your app, it will already have a copy of OpenSSL included. This can cause issues with the version of OpenSSL that NMSSH uses. You can disable flipper by removing/commenting out the flipper_configuration => flipper_config, line in your Podfile.

Android

No additional steps are needed for Android.

Linking

This project has been updated to use React Native v84 (the latest at the time of writing, Feb 2026) - which means that manual linking is not required.

Usage

All functions that run asynchronously where we have to wait for a result returns Promises that can reject if an error occurred.

[!NOTE] On iOS, this package currently doesn't support the simulator, you will need to have your app running on a physical device. If you would like to know more about this, see this issue. I'd welcome a PR to resolve this.

Create a client using password authentication

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

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

Create a client using public key authentication

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

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

Public key authentication is also supported

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

Close client

client.disconnect();

Execute SSH command

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

Shell

Start shell

  • Supported ptyType: vanilla, vt100, vt102, vt220, ansi, xterm
const ptyType = 'vanilla';
client.startShell(ptyType)
  .then(() => {/*...*/});

Read from shell

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

Write to shell

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

Close shell

client.closeShell();

SFTP

Connect SFTP

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

List directory

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

Create directory

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

Rename file or directory

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

Remove directory

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

Remove file

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

Download file

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();

Upload file

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();

Close SFTP

client.disconnectSFTP();

Example app

You can find a very simple example app for the usage of this library here.

Credits

This package wraps the following libraries, which provide the actual SSH/SFTP functionality:

This package is a fork of Emmanuel Natividad's react-native-ssh-sftp package. The fork chain from there is as follows:

  1. Gabriel Paul "Cley Faye" Risterucci
  2. Bishoy Mikhael
  3. Qian Sha

版本与发布记录

@dylankenneally/react-native-ssh-sftp 共发布 24 个版本,首次发布于 2024/01/17;过去 12 个月发布了 11 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.11.0latest2026/07/044 个月前
1.10.62026/07/044 个月前
1.10.02026/07/044 个月前
1.9.02026/07/044 个月前
1.8.02026/06/304 个月前
1.7.02026/03/277 个月前

关于 @dylankenneally/react-native-ssh-sftp 的常见问题

@dylankenneally/react-native-ssh-sftp 是什么?

SSH and SFTP client library for React Native

如何安装 @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 和提交记录判断。