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

node-ssh

Package Overview
Dependencies
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-ssh - npm Package Compare versions

Comparing version 4.0.1 to 4.1.0

8

CHANGELOG.md

@@ -0,1 +1,9 @@

#### 4.1.0
- Add sftp `opts` support in `getFile`, `putFile`, `putFiles` and `putDirectory`
#### 4.0.1
- Fix support for `config.sock`
#### 4.0.0

@@ -2,0 +10,0 @@

14

lib/helpers.js

@@ -8,2 +8,4 @@ 'use strict';

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var normalizeConfig = exports.normalizeConfig = function () {

@@ -15,4 +17,12 @@ var _ref = _asyncToGenerator(function* (givenConfig) {

}
if (typeof config.host !== 'string' || !config.host) {
throw new Error('config.host must be a valid string');
if (typeof config.host !== 'undefined') {
if (typeof config.host !== 'string' || !config.host) {
throw new Error('config.host must be a valid string');
}
} else if (typeof config.sock !== 'undefined') {
if (!config.sock || _typeof(config.sock) !== 'object') {
throw new Error('config.sock must be a valid object');
}
} else {
throw new Error('config.host or config.sock must be provided');
}

@@ -19,0 +29,0 @@ if (config.privateKey) {

81

lib/index.js

@@ -121,28 +121,26 @@ 'use strict';

} else {
yield* function* () {
(0, _assert2.default)(!givenSftp || (typeof givenSftp === 'undefined' ? 'undefined' : _typeof(givenSftp)) === 'object', 'sftp must be an object');
var sftp = givenSftp || (yield _this2.requestSFTP());
(0, _assert2.default)(!givenSftp || (typeof givenSftp === 'undefined' ? 'undefined' : _typeof(givenSftp)) === 'object', 'sftp must be an object');
var sftp = givenSftp || (yield this.requestSFTP());
var makeSftpDirectory = function makeSftpDirectory(retry) {
return Helpers.mkdirSftp(path, sftp).catch(function (error) {
if (retry && error && error.message === 'No such file') {
return _this2.mkdir(_path2.default.dirname(path), 'sftp', sftp).then(function () {
return makeSftpDirectory(false);
});
}
throw error;
});
};
try {
yield makeSftpDirectory(true);
} finally {
if (!givenSftp) {
sftp.end();
var makeSftpDirectory = function makeSftpDirectory(retry) {
return Helpers.mkdirSftp(path, sftp).catch(function (error) {
if (retry && error && error.message === 'No such file') {
return _this2.mkdir(_path2.default.dirname(path), 'sftp', sftp).then(function () {
return makeSftpDirectory(false);
});
}
throw error;
});
};
try {
yield makeSftpDirectory(true);
} finally {
if (!givenSftp) {
sftp.end();
}
}();
}
}
});
function mkdir(_x, _x2, _x3) {
function mkdir(_x) {
return _ref3.apply(this, arguments);

@@ -178,3 +176,3 @@ }

function exec(_x6, _x7, _x8) {
function exec(_x4) {
return _ref4.apply(this, arguments);

@@ -222,3 +220,3 @@ }

function execCommand(_x11, _x12) {
function execCommand(_x7) {
return _ref5.apply(this, arguments);

@@ -234,2 +232,3 @@ }

var givenSftp = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var givenOpts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;

@@ -240,7 +239,10 @@ (0, _assert2.default)(this.connection, 'Not connected to server');

(0, _assert2.default)(!givenSftp || (typeof givenSftp === 'undefined' ? 'undefined' : _typeof(givenSftp)) === 'object', 'sftp must be an object');
(0, _assert2.default)(!givenOpts || (typeof givenOpts === 'undefined' ? 'undefined' : _typeof(givenOpts)) === 'object', 'opts must be an object');
var opts = givenOpts || {};
var sftp = givenSftp || (yield this.requestSFTP());
try {
yield new Promise(function (resolve, reject) {
sftp.fastGet(remoteFile, localFile, Helpers.generateCallback(resolve, reject));
sftp.fastGet(remoteFile, localFile, opts, Helpers.generateCallback(resolve, reject));
});

@@ -254,3 +256,3 @@ } finally {

function getFile(_x14, _x15, _x16) {
function getFile(_x9, _x10) {
return _ref6.apply(this, arguments);

@@ -266,2 +268,3 @@ }

var givenSftp = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var givenOpts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;

@@ -272,5 +275,7 @@ (0, _assert2.default)(this.connection, 'Not connected to server');

(0, _assert2.default)(!givenSftp || (typeof givenSftp === 'undefined' ? 'undefined' : _typeof(givenSftp)) === 'object', 'sftp must be an object');
(0, _assert2.default)(!givenOpts || (typeof givenOpts === 'undefined' ? 'undefined' : _typeof(givenOpts)) === 'object', 'opts must be an object');
(0, _assert2.default)((yield Helpers.exists(localFile)), 'localFile does not exist at ' + localFile);
var that = this;
var opts = givenOpts || {};
var sftp = givenSftp || (yield this.requestSFTP());

@@ -280,3 +285,3 @@

return new Promise(function (resolve, reject) {
sftp.fastPut(localFile, remoteFile, Helpers.generateCallback(resolve, function (error) {
sftp.fastPut(localFile, remoteFile, opts, Helpers.generateCallback(resolve, function (error) {
if (error.message === 'No such file' && retry) {

@@ -302,3 +307,3 @@ resolve(that.mkdir(_path2.default.dirname(remoteFile), 'sftp', sftp).then(function () {

function putFile(_x18, _x19, _x20) {
function putFile(_x13, _x14) {
return _ref7.apply(this, arguments);

@@ -313,9 +318,12 @@ }

var _ref8 = _asyncToGenerator(function* (files) {
var givenSftp = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
var _this3 = this;
var givenSftp = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
var maxAtOnce = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 5;
var givenOpts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
(0, _assert2.default)(this.connection, 'Not connected to server');
(0, _assert2.default)(!givenSftp || (typeof givenSftp === 'undefined' ? 'undefined' : _typeof(givenSftp)) === 'object', 'sftp must be an object');
(0, _assert2.default)(!givenOpts || (typeof givenOpts === 'undefined' ? 'undefined' : _typeof(givenOpts)) === 'object', 'opts must be an object');
(0, _assert2.default)(Array.isArray(files), 'files must be an array');

@@ -331,2 +339,3 @@ (0, _assert2.default)(typeof maxAtOnce === 'number' && Number.isFinite(maxAtOnce), 'maxAtOnce must be a valid number');

var opts = givenOpts || {};
var sftp = givenSftp || (yield this.requestSFTP());

@@ -340,3 +349,3 @@ var transferred = [];

yield Promise.all(chunk.map(function (file) {
return _this3.putFile(file.local, file.remote, sftp);
return _this3.putFile(file.local, file.remote, sftp, opts);
}));

@@ -355,3 +364,3 @@ transferred = transferred.concat(chunk);

function putFiles(_x22, _x23, _x24) {
function putFiles(_x17) {
return _ref8.apply(this, arguments);

@@ -366,6 +375,8 @@ }

var _ref9 = _asyncToGenerator(function* (localDirectory, remoteDirectory) {
var givenConfig = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var _this4 = this;
var givenConfig = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var givenSftp = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
var givenOpts = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null;

@@ -378,3 +389,6 @@ (0, _assert2.default)(this.connection, 'Not connected to server');

(0, _assert2.default)((typeof givenConfig === 'undefined' ? 'undefined' : _typeof(givenConfig)) === 'object' && givenConfig, 'config must be an object');
(0, _assert2.default)(!givenSftp || (typeof givenSftp === 'undefined' ? 'undefined' : _typeof(givenSftp)) === 'object', 'sftp must be an object');
(0, _assert2.default)(!givenOpts || (typeof givenOpts === 'undefined' ? 'undefined' : _typeof(givenOpts)) === 'object', 'opts must be an object');
var opts = givenOpts || {};
var sftp = givenSftp || (yield this.requestSFTP());

@@ -387,2 +401,3 @@ var config = Helpers.normalizePutDirectoryConfig(givenConfig);

// eslint-disable-next-line arrow-parens
var promises = files.map(function () {

@@ -398,3 +413,3 @@ var _ref10 = _asyncToGenerator(function* (file) {

try {
yield _this4.putFile(localFile, remoteFile, sftp);
yield _this4.putFile(localFile, remoteFile, sftp, opts);
config.tick(localFile, remoteFile, null);

@@ -408,3 +423,3 @@ return true;

return function (_x33) {
return function (_x26) {
return _ref10.apply(this, arguments);

@@ -428,3 +443,3 @@ };

function putDirectory(_x27, _x28, _x29, _x30) {
function putDirectory(_x21, _x22) {
return _ref9.apply(this, arguments);

@@ -431,0 +446,0 @@ }

{
"name": "node-ssh",
"version": "4.0.1",
"version": "4.1.0",
"description": "SS2 with Promises",

@@ -35,5 +35,5 @@ "main": "lib/index.js",

"babel-cli": "^6.11.4",
"babel-preset-steelbrain": "^4.0.2",
"eslint-config-steelbrain": "^1.0.4",
"flow-bin": "^0.32.0",
"babel-preset-steelbrain": "^5.0.0",
"eslint-config-steelbrain": "^2.0.0",
"flow-bin": "^0.42.0",
"jasmine-fix": "^1.0.1",

@@ -40,0 +40,0 @@ "pty.js": "^0.3.1",

Node-SSH - SSH2 with Promises
=========
[![Greenkeeper badge](https://badges.greenkeeper.io/steelbrain/node-ssh.svg)](https://greenkeeper.io/)
Node-SSH is an extremely lightweight Promise wrapper for [ssh2][ssh2], Period.

@@ -96,6 +98,6 @@

execCommand(command: string, options: { cwd: string, stdin: string } = {}): Promise<{ stdout: string, stderr: string, signal: ?string, code: number }>
putFile(localFile: string, remoteFile: string, sftp: ?Object = null): Promise<void>
getFile(localFile: string, remoteFile: string, sftp: ?Object = null): Promise<void>
putFiles(files: Array<{ local: string, remote: string }>, sftp: ?Object = null, maxAtOnce: number = 5): Promise<void>
putDirectory(localDirectory: string, remoteDirectory: string, options: ?{ recursive: boolean, tick(localPath, remotePath, error): any, validate(localPath): boolean } = null, sftp: ?Object = null): Promise<boolean>
putFile(localFile: string, remoteFile: string, sftp: ?Object = null, opts: ?Object = null): Promise<void>
getFile(localFile: string, remoteFile: string, sftp: ?Object = null, opts: ?Object = null): Promise<void>
putFiles(files: Array<{ local: string, remote: string }>, sftp: ?Object = null, maxAtOnce: number = 5, opts: ?Object = null): Promise<void>
putDirectory(localDirectory: string, remoteDirectory: string, options: ?{ recursive: boolean, tick(localPath, remotePath, error): any, validate(localPath): boolean } = null, sftp: ?Object = null, opts: ?Object = null): Promise<boolean>
dispose(): void

@@ -102,0 +104,0 @@ }

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