node.js - Access SFTP from NodeJS -
i have need have open sftp connection server, copy file there local.
to end, have tried installing node-sftp module using
npm install node-sftp
it didnt work out of box, had replace sftp.js file installed npm of github repository here : https://github.com/ajaxorg/node-sftp
(npm version using tty , github version using pty. not sure are)
after start server , invoking code, see in console.
launching: sftp -o port=22 jash@xxx.63.xxx.49 listening...
console hangs here. trying print files in current directory after connection opened.
this code
var http = require('http'); var sftp = require('node-sftp'); var port = process.env.port || 1337; var msghandler = function(request, response) { var options = { host:"xxx.63.xxx.49", username:"jash", password:"mypassword", port:22 }; var conn = new sftp(options,function(err){ console.log(err); }); conn.cd(".", function(err) { console.log(err); conn.ls(".", function(err, res) { console.log(res[0].path); }); }); console.log("listening..."); } http.createserver(msghandler).listen(port);
the credentials fine, used them in securecrt , able login.
the second argument sftp()
(the function(err)...
) want place conn.cd(...
code. (said 2nd argument) function gets called once connection has been established. make sure check err
of course.
Comments
Post a Comment