https://www.npmjs.com/package/ssh2
npm install ssh2
ssh2文件下载:
1 //前台命令下发 2 app.get('/test/fileDownload', function (req, res) { 3 var downloadPath = req.query.downloadPath; 4 console.log(downloadPath); 5 6 var conn = new Client(); 7 conn.on('ready', function() { 8 console.log('Client :: ready'); 9 conn.sftp(function(err, sftp) { 10 if (err) throw err; 11 //sftp.fastPut('/home/admin/foo/expdat.log','/home/book/foo/expdat.log', function(err, list) { 12 sftp.fastGet('/home/book/foo/expdat.log','/home/admin/foo/expdat.log' ,function(err, result) { 13 if (err) throw err; 14 //console.log('----------GET BEGIN!-------------'); 15 res.download(downloadPath); 16 //console.log('----------GET END!-------------'); 17 conn.end(); 18 }); 19 }); 20 }).connect({ 21 host: '192.168.0.111', 22 port: 22, 23 username: 'admin', 24 password: 'admin' 25 }); 26 });