我使用“simple-ssh”节点模块执行远程shell脚本并在远程系统中创建日志文件。我的要求是将此远程文件通过电子邮件发送到某个电子邮
步骤1:执行将生成日志文件的远程shell脚本 var SSH = require('simple-ssh');
var ssh = new SSH({
host: 'remotehost',
user: 'username',
pass: 'password'
});
ssh.exec('someshellscript.sh ', {
out: function(stdout) {
console.log(stdout);
}
}).start();
步骤2:使用ssh2将文件从远程系统复制到本地
var Client = require('ssh2').Client;
var connSettings = {
host: 'remotehost',
port: 22,
username: 'username',
password: 'password'
};
var conn = new Client();
conn.on('ready', function() {
conn.sftp(function(err, sftp) {
if (err) throw err;
var moveFrom = "/remote/file/path/file.txt";
var moveTo = "/local/file/path/file.txt";
sftp.fastGet(moveFrom, moveTo , {}, function(downloadError){
if(downloadError) throw downloadError;
console.log("Succesfully uploaded");
});
});
}).connect(connSettings);
在发送电子邮件之前,有没有更好的方法可以避免在本地系统中复制文件? filestream API可以这样做吗?