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 🙏

© 2025 – Pkg Stats / Ryan Hefner

ssh-client-wrapper

v2.14.0

Published

wrapper library for open ssh client and rsync

Readme

npm version Known Vulnerabilities Test Coverage Maintainability

ssh-client-wrapper

open ssh client wrapper library for nodejs

Installation

npm install ssh-client-wrapper

Usage

Here is a simple example of how to use ssh-client-wrapper to execute a command on a remote server.

import SshClientWrapper from 'ssh-client-wrapper';

const hostInfo = {
  host: 'remote.server.com',
  port: 22,
  user: 'username',
  password: 'password'
};

const ssh = new SshClientWrapper(hostInfo);

async function run() {
  try {
    await ssh.canConnect();
    console.log('Connection successful!');

    const { output, rt } = await ssh.execAndGetOutput('ls -l /home');
    if (rt === 0) {
      console.log('Directory listing:');
      output.forEach(line => console.log(line));
    } else {
      console.error('Error executing command');
    }
  } catch (err) {
    console.error('Connection or command failed:', err);
  } finally {
    ssh.disconnect();
  }
}

run();

API Guide

new SshClientWrapper(hostInfo)

Creates a new SSH client instance.

  • hostInfo (Object): Connection details for the remote host.
    • host (string): The hostname or IP address of the server.
    • user (string): The username for authentication.
    • port (number, optional): The port number. Defaults to 22.
    • password (string | Function, optional): The password for authentication, or a function that returns the password.
    • keyFile (string, optional): The path to the private key file for key-based authentication.
    • passphrase (string | Function, optional): The passphrase for the private key, or a function that returns it.
    • noStrictHostKeyChecking (boolean, optional): If true, bypasses strict host key checking.
    • And more... see lib/index.js for all available options.

.exec(cmd, [timeout], [outputCallback], [rcfile], [prependCmd])

Executes a command on the remote host.

  • Returns: Promise<number> - The return code of the command.

.execAndGetOutput(cmd, [timeout], [rcfile], [prependCmd])

Executes a command and returns its standard output.

  • Returns: Promise<{output: string[], rt: number}> - An object containing the output as an array of strings and the return code.

.ls(target, [lsOpt], [timeout])

Executes the ls command on the remote host.

  • Returns: Promise<string[]> - The output of the ls command as an array of strings.

.expect(cmd, expects, [timeout])

Executes a command and interacts with it, similar to the expect tool.

  • Returns: Promise<number> - The return code of the command.

.send(src, dst, [opt], [timeout])

Uploads files or directories to the remote host using rsync.

  • src (string[]): An array of local paths to send.
  • dst (string): The remote destination path.
  • Returns: Promise<void>

.recv(src, dst, [opt], [timeout])

Downloads files or directories from the remote host using rsync.

  • src (string[]): An array of remote paths to receive.
  • dst (string): The local destination path.
  • Returns: Promise<void>

.canConnect([timeout])

Checks if a connection to the remote host can be established.

  • Returns: Promise<boolean> - Resolves with true on success.

.disconnect()

Closes the master SSH connection to the remote host.