Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ssh2-streams

Package Overview
Dependencies
Maintainers
1
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ssh2-streams

SSH2 and SFTP(v3) client/server protocol streams for node.js

  • 0.4.10
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.5M
increased by11.35%
Maintainers
1
Weekly downloads
 
Created

What is ssh2-streams?

The ssh2-streams npm package provides a set of utilities for working with SSH2 protocol streams. It is commonly used for creating and managing SSH connections, executing commands, and transferring files over SFTP.

What are ssh2-streams's main functionalities?

Creating an SSH Connection

This code demonstrates how to create an SSH connection using the ssh2-streams package. It connects to an SSH server, executes the 'uptime' command, and handles the output and errors.

const { Client } = require('ssh2-streams');
const conn = new Client();
conn.on('ready', () => {
  console.log('Client :: ready');
  conn.exec('uptime', (err, stream) => {
    if (err) throw err;
    stream.on('close', (code, signal) => {
      console.log('Stream :: close :: code: ' + code + ', signal: ' + signal);
      conn.end();
    }).on('data', (data) => {
      console.log('STDOUT: ' + data);
    }).stderr.on('data', (data) => {
      console.log('STDERR: ' + data);
    });
  });
}).connect({
  host: '127.0.0.1',
  port: 22,
  username: 'frylock',
  privateKey: require('fs').readFileSync('/here/is/my/key')
});

SFTP File Transfer

This code demonstrates how to transfer a file using SFTP with the ssh2-streams package. It connects to an SSH server, initiates an SFTP session, and downloads a file from the remote server to the local machine.

const { Client } = require('ssh2-streams');
const conn = new Client();
conn.on('ready', () => {
  console.log('Client :: ready');
  conn.sftp((err, sftp) => {
    if (err) throw err;
    sftp.fastGet('/remote/path/file.txt', '/local/path/file.txt', (err) => {
      if (err) throw err;
      console.log('File transferred successfully');
      conn.end();
    });
  });
}).connect({
  host: '127.0.0.1',
  port: 22,
  username: 'frylock',
  privateKey: require('fs').readFileSync('/here/is/my/key')
});

Other packages similar to ssh2-streams

Keywords

FAQs

Package last updated on 16 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc