npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ridenui/react-native-ssh-sftp

v1.1.0

Published

SSH and SFTP client library for React Native.

Downloads

1

Readme

react-native-ssh-sftp

SSH and SFTP client library for React Native.

Installation

npm install react-native-ssh-sftp --save
react-native link react-native-ssh-sftp

iOS (only)

NMSSH is required for iOS.

  1. Initialize Pod:
    cd ios
    pod init
  2. Open Podfile and add:
    target '[your project's name]' do
    	pod 'NMSSH', '2.2.8'
    end
  3. Install Pod:
    pod install

Manual Link

iOS

  1. In XCode, in the project navigator, right click LibrariesAdd Files to [your project's name]
  2. Go to node_modulesreact-native-ssh-sftp and add RNSSHClient.xcodeproj
  3. In XCode, in the project navigator, select your project. Add libRNSSHClient.a to your project's Build PhasesLink Binary With Libraries

Android

  1. Open up android/app/src/main/java/[...]/MainActivity.java - Add import com.reactlibrary.RNSshClientPackage; to the imports at the top of the file - Add new RNSshClientPackage() to the list returned by the getPackages() method
  2. Append the following lines to android/settings.gradle:
    include ':react-native-ssh-sftp'
    project(':react-native-ssh-sftp').projectDir = new File(rootProject.projectDir, 	'../node_modules/react-native-ssh-sftp/android')
  3. Insert the following lines inside the dependencies block in android/app/build.gradle:
    compile project(':react-native-ssh-sftp')

Demo

example

  • This library is also used in iOS app PiHelper.

Run demo

iOS

cd example
cd ios
pod install
cd ..
npm install
react-native run-ios

Android

cd example
npm install
react-native run-android

Usage

Create a client using password authentication

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

let client = new SSHClient('10.0.0.10', 22, 'user', 'password', (error) => {
  if (error)
    console.warn(error);
});

Create a client using public key authentication

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

let client = new SSHClient('10.0.0.10', 22, 'user', {privateKey: '-----BEGIN RSA......'}, (error) => {
  if (error)
    console.warn(error);
});
  • Public key authentication also supports:
{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

var command = 'ls -l';
client.execute(command, (error, output) => {
  if (error)
    console.warn(error);
  if (output)
    console.warn(output);
});

Shell

Start shell:

  • Supported ptyType: vanilla, vt100, vt102, vt220, ansi, xterm
var ptyType = 'vanilla';
client.startShell(ptyType, (error) => {
  if (error)
    console.warn(error);
});

Read from shell:

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

Write to shell:

var str = 'ls -l\n';
client.writeToShell(str, (error) => {
  if (error) 
    console.warn(error);
});

Close shell:

client.closeShell();

SFTP

Connect SFTP

client.connectSFTP((error) => {
  if (error)
    console.warn(error);
});

List directory:

var path = '.';
client.sftpLs(path, (error, response) => {
  if (error)
    console.warn(error);
  if (response)
    console.warn(response);
});

Create directory:

client.sftpMkdir('dirName', (error) => {
  if (error)
    console.warn(error);
});

Rename file or directory:

client.sftpRename('oldName', 'newName', (error) => {
  if (error)
    console.warn(error);
});

Remove directory:

client.sftpRmdir('dirName', (error) => {
  if (error)
    console.warn(error);
});

Remove file:

client.sftpRm('fileName', (error) => {
  if (error)
    console.warn(error);
});

Download file:

client.sftpDownload('[path-to-remote-file]', '[path-to-local-direcotry]', (error, downloadedFilePath) => {
  if (error)
    console.warn(error);
  if (downloadedFilePath)
    console.warn(downloadedFilePath);
});

// Downlowd progress
client.on('DownloadProgress', (event) => {
  console.warn(event);
});

// Cancel download:
client.sftpCancelDownload();

Upload file:

client.sftpUpload('[path-to-local-file]', '[path-to-remote-directory]', (error) => {
  if (error)
    console.warn(error);
});

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

// Cancel upload:
client.sftpCancelUpload();

Close SFTP:

client.disconnectSFTP();

Credits

  • iOS SSH library: NMSSH
  • Android SSH library: JSch