🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
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.0.1
Source
npm
Version published
Weekly downloads
1.6M
1.51%
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

ssh

FAQs

Package last updated on 25 Jan 2015

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