Git Product home page Git Product logo

sftp-promises's Introduction

sftp-promises

NPM versionCoverage Status

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

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.

Streams

The current streams implementation requires supplying either readable or writable streams and do not return promises with streams like the getBuffer method. This is to support non-presistent connections which would drop if a stream was returned on the promise resolve.

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(<string>remote_path, [ssh2.Connection]session) returns a promise with on object containing path attributes
sftp.ls(<string>remote_path, [ssh2.Connection]session) returns a promise with an object descibing the path
sftp.getBuffer(<string>remote_path, [ssh2.Connection]session) returns a promise with a buffer containing the file contents
sftp.putBuffer(<Buffer>data, <string>remote_path, [ssh2.Connection]session) returns a promise with a boolean, true if successful
sftp.get(<string>remote_path, <string>local_path, [ssh2.Connection]session) returns a promise with a boolean, true if successful
sftp.put(<string>local_path, <string>remote_path, [ssh2.Connection]session) returns a promise with a boolean, true if successful
sftp.rm(<string>location, [ssh2.Connection]session) returns a promise with a boolean, true if successful
sftp.mv(<string>src, <string>dest, [ssh2.Connection]session) returns a promise with a boolean, true if successful sftp.mkdir(<string>path, [ssh2.Connection]session) returns a promise with a boolean, true if successful sftp.rmdir(<string>path, [ssh2.Connection]session) returns a promise with a boolean, true if successful sftp.getStream(<string>path, writableStream, [ssh2.Connection]session) returns a promise with a boolean, true if stream write completed sftp.putStream(<string>path, writableStream, [ssh2.Connection]session) returns a promise with a boolean, true is stream write completed

Planned Features/Updates

  • have test rely on ssh2.server instead of local ssh server

sftp-promises's People

Contributors

brokenbot avatar

Watchers

James Cloos avatar jim mitchell avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.