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

yocto-sftp

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

yocto-sftp

This is an wrapper of SSH2 library to simply create sftp connection.

  • 0.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

NPM

alt text Code Climate Test Coverage Issue Count Build Status

Overview

This module is a part of yocto node modules for NodeJS.

Please see our NPM repository for complete list of available tools (completed day after day).

This module provide a simple sitemap generator based sitemap-generator.

Motivation

Create an simple module that create a sftp client with SSH2 library.

Specification

This is an wrapper of SSH2 library. All methods handle automatic connect and close process to the ftp server.

Ftp method implemented

  • get
  • delete
  • put
  • ls
  • mkdir (with mkdirp)

Usage

Basic configuration

Configure module, configuration object will be check by an Joi schema

var logger    = require('yocto-logger');
var sftp      = require('yocto-sftp')(logger);

var config = {
  host        : "10.10.10.10",
  port        : 22,
  user        : "test",
  password    : "pwd",
  algorithms  : {
    serverHostKey: [ 'ssh-rsa', 'ssh-dss' ],
  },
  agent       : process.env.SSH_AUTH_SOCK
};


// path dir to list
var pathDir = '/jumbodrive.re/ads/';

// connect
sftp.load(config).then(function () {
  console.log('\n --> config success ... ');
  // connect to client
  sftp.connect().then(function(client) {
    // the client is :
    // {  
    //    // ssh2 instance
    //    client : client,
    //    // sftp instance
    //    sftp   : sftp
    // }
    console.log('\n --> connect success ');

    setTimeout(function () {
      console.log('\n --> end client connection ...');
      // manually close the connect
      sftp.end(client);
    }, 2000);
  }).catch(function (error) {
    console.log('\n --> connect failed ', error);
  });
}).catch(function (error) {
  console.log('\n --> error : ', error);
});

Get an document

This method download an file from sftp server


var localPathFile   = '/toto';
var remotePathFile  =  '/tata';

// connect
sftp.load(config).then(function () {
  console.log('\n --> config success ... ');

  sftp.get(localPathFile, remotePathFile).then(function (list) {
    console.log('\n --> ls success \n', list);

  }).catch(function (error) {
    console.log('\n --> ls failed ', error);
  });
}).catch(function (error) {
  console.log('\n --> error : ', error);
});

List directory

This method return an array of files description from ftp server


var remotePathFOlder  =  '/tata/';

// connect
sftp.load(config).then(function () {
  console.log('\n --> config success ... ');

  sftp.ls(remotePathFOlder).then(function (list) {
    console.log('\n --> ls success \n', list);

  }).catch(function (error) {
    console.log('\n --> ls failed ', error);
  });
}).catch(function (error) {
  console.log('\n --> error : ', error);
});

Delete an document

This method remove an file in sftp server


var remotePathFile  =  '/tata.png';

// connect
sftp.load(config).then(function () {
  console.log('\n --> config success ... ');

  sftp.delete(remotePathFile).then(function (list) {
    console.log('\n --> ls success \n', list);

  }).catch(function (error) {
    console.log('\n --> ls failed ', error);
  });
}).catch(function (error) {
  console.log('\n --> error : ', error);
});

Put an document

This method upload an file in sftp server


var localPathFile   = '/toto';
var remotePathFile  =  '/tata';

// connect
sftp.load(config).then(function () {
  console.log('\n --> config success ... ');

  sftp.put(localPathFile, remotePathFile).then(function (list) {
    console.log('\n --> ls success \n', list);

  }).catch(function (error) {
    console.log('\n --> ls failed ', error);
  });
}).catch(function (error) {
  console.log('\n --> error : ', error);
});

Check if an file exit on ftp server

This Check if an file exit on ftp server


var remotePathFile  =  '/tata';

// connect
sftp.load(config).then(function () {
  console.log('\n --> config success ... ');

  sftp.fileExist(remotePathFile).then(function (list) {
    console.log('\n --> ls success \n', list);

  }).catch(function (error) {
    console.log('\n --> ls failed ', error);
  });
}).catch(function (error) {
  console.log('\n --> error : ', error);
});

Create folder and its own parent if speciefied

This Create folder into sftp


var remotePathFOlder  =  '/toto/tata/titi/tutu';
// If true parent folder will be created otherwise none
var createParent = true;

// connect
sftp.load(config).then(function () {
  console.log('\n --> config success ... ');

  sftp.mkdir(remotePathFile, createParent).then(function (list) {
    console.log('\n --> create success \n', list);

  }).catch(function (error) {
    console.log('\n --> create failed ', error);
  });
}).catch(function (error) {
  console.log('\n --> error : ', error);
});

FAQs

Package last updated on 16 Jun 2017

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

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