npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

yocto-sftp

v0.2.0

Published

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

Downloads

7

Readme

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);
});