1.8.0 • Published 3 years ago

sftp-promises v1.8.0

Weekly downloads
3,771
License
BSD-3-Clause
Repository
github
Last release
3 years ago

sftp-promises

NPM versionCoverage StatusBuild StatusGitpod ready-to-code

SFTP Promise Wrapper for ssh2

Support basic SFTP transaction with promises, specifically for fronting SFTP with a web based API using something like Koa

Warning

By default each request will create a new conneciton and close it when finished, this is by design as its intended to be used in stateless web applications. As such care should exercised when using on high traffic systems to avoid too many connections to SFTP server and general connection overhead.

Usage

One connection per call

var config = {host: 'localhost', username: 'user', password: 'pass' };
var SFTPClient = require('sftp-promises');
var sftp = new SFTPClient(config);
     
sftp.ls('.').then(function(list) { console.log(list) })

Persistent Session calls (Experimental)

var config = {host: 'localhost', username: 'user', password: 'pass' };
var SFTPClient = require('sftp-promises');
var sftp = new SFTPClient();

// get session
var session = sftp.session(config).then(function(ftpSession) { session = ftpSession })
...code to ensure session is ready...  
sftp.ls('.', session).then(function(list) { console.log(list) })

// close socket
session.end()

config options are the same as ssh2 config options.

Supported calls

All calls take an optional ssh2 Connction object as the final arguement for using persistent session.

sftp.stat(\remote_path, ssh2.Connectionsession) returns a promise with on object containing path attributes
sftp.ls(\remote_path, ssh2.Connectionsession) returns a promise with an object descibing the path
sftp.getBuffer(\remote_path, ssh2.Connectionsession) returns a promise with a buffer containing the file contents
sftp.putBuffer(\data, \remote_path, ssh2.Connectionsession) returns a promise with a boolean, true if successful
sftp.get(\remote_path, \local_path, ssh2.Connectionsession) returns a promise with a boolean, true if successful
sftp.put(\local_path, \remote_path, ssh2.Connectionsession) returns a promise with a boolean, true if successful
sftp.rm(\location, ssh2.Connectionsession) returns a promise with a boolean, true if successful
sftp.mv(\src, \dest, ssh2.Connectionsession) returns a promise with a boolean, true if successful sftp.mkdir(\path, ssh2.Connectionsession) returns a promise with a boolean, true if successful sftp.rmdir(\path, ssh2.Connectionsession) returns a promise with a boolean, true if successful sftp.getStream(\path, writableStream, ssh2.Connectionsession) returns a promise with a boolean, true if stream write completed
sftp.putStream(\path, writableStream, ssh2.Connectionsession) returns a promise with a boolean, true is stream write completed
sftp.createReadStream(\path, ssh2.Connectionsession) returns a promise with a readStream (ssh session will terminate on streams events close and error)
sftp.createWriteStream(\path, ssh2.Connectionsession) returns a promise with a writeStream (ssh session will terminate on streams events close and error)

ToDo

  • better testing of sessions
  • validate sftp session is actually a valid ssh session
  • mkdir recursive
  • rmdir recursive
  • ability to add options to be passed to underlying ssh2 connections
  • better documentation
1.8.0

3 years ago

1.7.1

5 years ago

1.7.0

6 years ago

1.6.0

7 years ago

1.5.2

7 years ago

1.5.1

7 years ago

1.5.0

7 years ago

1.4.2

8 years ago

1.4.1

8 years ago

1.4.0

8 years ago

1.3.0

9 years ago

1.2.4

9 years ago

1.2.2

9 years ago

1.2.1

9 years ago

1.2.0

9 years ago

1.1.1

9 years ago

1.1.0

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago

0.0.1

9 years ago