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

ssh2-sftp-client

Package Overview
Dependencies
Maintainers
1
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ssh2-sftp-client - npm Package Compare versions

Comparing version 3.0.0 to 3.1.0

LICENSE

4

package.json
{
"name": "ssh2-sftp-client",
"version": "3.0.0",
"version": "3.1.0",
"description": "ssh2 sftp client for node",

@@ -21,3 +21,3 @@ "main": "src/index.js",

"dependencies": {
"ssh2": "^0.5.5"
"ssh2": "^0.6.1"
},

@@ -24,0 +24,0 @@ "devDependencies": {

@@ -59,4 +59,2 @@ ## SSH2 SFTP Client

> Before V3.0.0, `get` method will return new readable stream from remotePath.
```javascript

@@ -66,2 +64,9 @@ sftp.get(remoteFilePath, [useCompression], [encoding], [addtionalOptions]);

#### FastGet
Downloads a file at remotePath to localPath using parallel reads for faster throughput. [options properties](https://github.com/mscdex/ssh2-streams/blob/master/SFTPStream.md) you can find `fastGet` method here.
```javascript
sftp.fastGet(remotePath, localPath, [options]);
```
#### Put

@@ -76,2 +81,9 @@ upload a file from `localPath` or `Buffer`, `Stream` data to `remoteFilePath`.The encoding is passed to Node Stream to control how the content is encoded. Default to 'utf8'.

#### FastPut
Uploads a file from localPath to remotePath using parallel reads for faster throughput. [options properties](https://github.com/mscdex/ssh2-streams/blob/master/SFTPStream.md) you can find `fastPut` method here.
```javascript
sftp.fastPut(localPath, remotePath, [options]);
```
#### Mkdir

@@ -151,3 +163,11 @@ create a new directory.

### Log
#### V3.0.0
#### V3.1.0
- update: upgrade `ssh2` to `0.6.1`
#### V2.3.0
- add: `stat` method
- add `fastGet` and `fastPut` method.
- fix: `mkdir` file exists decision logic
#### V3.0.0 -- deprecate this version
- change: `sftp.get` will return chunk not stream anymore

@@ -154,0 +174,0 @@ - fix: get readable not emitting data events in node 10.0.0

@@ -25,2 +25,5 @@ /**

if (sftp) {
this.client.on('error', (err) => {
reject(err);
});
sftp.readdir(path, (err, list) => {

@@ -57,2 +60,37 @@ if (err) {

/**
* Retrieves attributes for path
*
* @param {String} path, a string containing the path to a file
* @return {Promise} stats, attributes info
*/
SftpClient.prototype.stat = function(remotePath) {
return new Promise((resolve, reject) => {
let sftp = this.sftp;
if (sftp) {
sftp.stat(remotePath, function (err, stats) {
if (err){
return reject(err);
}
// format output similarly to sftp.list()
stats = {
mode: stats.mode,
permissions: stats.permissions,
owner: stats.uid,
group: stats.guid,
size: stats.size,
accessTime: stats.atime * 1000,
modifyTime: stats.mtime * 1000
}
return resolve(stats);
});
} else {
reject(Error('sftp connect error'));
}
});
};
/**
* get file

@@ -73,2 +111,6 @@ *

try {
this.client.on('error', (err) => {
reject(err);
});
let stream = sftp.createReadStream(path, options);

@@ -79,9 +121,4 @@

});
// after V10.0.0, 'readable' takes precedence in controlling the flow,
// i.e. 'data' will be emitted only when stream.read() is called
stream.on('readable', () => {
let chunk;
while((chunk = stream.read()) !== null) {
resolve(chunk)
}
resolve(stream);
});

@@ -98,2 +135,57 @@ } catch(err) {

/**
* Use SSH2 fastGet for downloading the file.
* Downloads a file at remotePath to localPath using parallel reads for faster throughput.
* See 'fastGet' at https://github.com/mscdex/ssh2-streams/blob/master/SFTPStream.md
* @param {String} remotePath
* @param {String} localPath
* @param {Object} options
* @return {Promise} the result of downloading the file
*/
SftpClient.prototype.fastGet = function(remotePath, localPath, options) {
options = options || {};
return new Promise((resolve, reject) => {
let sftp = this.sftp;
if (sftp) {
sftp.fastGet(remotePath, localPath, options, function (err) {
if (err){
return reject(err);
}
return resolve(`${remotePath} was successfully download to ${localPath}!`);
});
} else {
reject(Error('sftp connect error'));
}
});
};
/**
* Use SSH2 fastPut for uploading the file.
* Uploads a file from localPath to remotePath using parallel reads for faster throughput.
* See 'fastPut' at https://github.com/mscdex/ssh2-streams/blob/master/SFTPStream.md
* @param {String} localPath
* @param {String} remotePath
* @param {Object} options
* @return {Promise} the result of downloading the file
*/
SftpClient.prototype.fastPut = function(localPath, remotePath, options) {
options = options || {};
return new Promise((resolve, reject) => {
let sftp = this.sftp;
if (sftp) {
sftp.fastPut(localPath, remotePath, options, function (err) {
if (err){
return reject(err);
}
return resolve(`${localPath} was successfully uploaded to ${remotePath}!`);
});
} else {
reject(Error('sftp connect error'));
}
});
};
/**
* Create file

@@ -114,2 +206,6 @@ *

if (sftp) {
this.client.on('error', (err) => {
reject(err);
});
if (typeof input === 'string') {

@@ -149,2 +245,6 @@ sftp.fastPut(input, remotePath, options, (err) => {

if (sftp) {
this.client.on('error', (err) => {
reject(err);
});
if (!recursive) {

@@ -174,3 +274,3 @@ sftp.mkdir(path, (err) => {

sftp.mkdir(p, (err) => {
if (err && err.code !== 4) {
if (err && ![4, 11].includes(err.code)) {
reject(err);

@@ -195,2 +295,6 @@ }

if (sftp) {
this.client.on('error', (err) => {
reject(err);
});
if (!recursive) {

@@ -265,2 +369,6 @@ return sftp.rmdir(path, (err) => {

if (sftp) {
this.client.on('error', (err) => {
reject(err);
});
sftp.unlink(path, (err) => {

@@ -284,2 +392,6 @@ if (err) {

if (sftp) {
this.client.on('error', (err) => {
reject(err);
});
sftp.rename(srcPath, remotePath, (err) => {

@@ -303,2 +415,6 @@ if (err) {

if (sftp) {
this.client.on('error', (err) => {
reject(err);
});
sftp.chmod(remotePath, mode, (err) => {

@@ -330,3 +446,2 @@ if (err) {

}).on('error', (err) => {
console.log('connect error event')
reject(err);

@@ -333,0 +448,0 @@ }).connect(config);

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