🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

node-ssh

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-ssh

SSH2 with Promises

13.2.1
latest
Version published
Weekly downloads
209K
1.03%
Maintainers
0
Weekly downloads
 
Created

What is node-ssh?

The node-ssh npm package is a lightweight wrapper for SSH2, providing a simple and easy-to-use API for performing SSH operations. It allows you to connect to remote servers, execute commands, transfer files, and manage SSH connections programmatically.

What are node-ssh's main functionalities?

Connecting to a remote server

This feature allows you to establish an SSH connection to a remote server using the provided host, username, and private key.

const { NodeSSH } = require('node-ssh');
const ssh = new NodeSSH();
ssh.connect({
  host: 'example.com',
  username: 'user',
  privateKey: '/path/to/private/key'
}).then(() => {
  console.log('Connected to the server');
}).catch(err => {
  console.error('Error connecting to the server:', err);
});

Executing commands on a remote server

This feature allows you to execute shell commands on the connected remote server and retrieve the output.

ssh.execCommand('ls -la', { cwd: '/home/user' }).then(result => {
  console.log('STDOUT: ' + result.stdout);
  console.log('STDERR: ' + result.stderr);
}).catch(err => {
  console.error('Error executing command:', err);
});

Transferring files to a remote server

This feature allows you to transfer files from your local machine to the remote server.

ssh.putFile('/local/path/to/file.txt', '/remote/path/to/file.txt').then(() => {
  console.log('File transferred successfully');
}).catch(err => {
  console.error('Error transferring file:', err);
});

Transferring files from a remote server

This feature allows you to download files from the remote server to your local machine.

ssh.getFile('/local/path/to/file.txt', '/remote/path/to/file.txt').then(() => {
  console.log('File downloaded successfully');
}).catch(err => {
  console.error('Error downloading file:', err);
});

Other packages similar to node-ssh

Keywords

FAQs

Package last updated on 20 Mar 2025

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