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
};
var pathDir = '/jumbodrive.re/ads/';
sftp.load(config).then(function () {
console.log('\n --> config success ... ');
sftp.connect().then(function(client) {
console.log('\n --> connect success ');
setTimeout(function () {
console.log('\n --> end client connection ...');
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';
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/';
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';
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';
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';
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';
var createParent = true;
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);
});