简体   繁体   English

无法使用节点ssh2从目录下载所有文件

[英]Not able to download all files from a directory using node ssh2

I was trying to download few files using ssh2 package in node. 我试图在节点中使用ssh2软件包下载一些文件。 I'm presently using 我目前正在使用

sftp.fastGet(remote_PATH, local_PATH, {}, function(downloadError){
    if(downloadError) throw downloadError;
      console.log("Succesfully downloaded");
    });

But not able to download all the files present in the directory. 但是无法下载目录中存在的所有文件。 Is it possible using this module? 是否可以使用此模块? If yes, how? 如果是,怎么办?

If you have full ssh access, one simple solution is to just stream a tar archive. 如果您具有完全的ssh访问权限,则一种简单的解决方案是仅流式处理tar存档。 For example: 例如:

var spawn = require('child_process').spawn;

// ...

ssh.exec('tar czf - /path/to/transfer', function(err, stream) {
  if (err) throw err;
  var localproc = spawn('tar', ['-C', '/path/to/extract/to', 'xf', '-']);
  stream.pipe(localproc);
  stream.on('close', function(code, signal) {
    console.log('Tar finished with code %j, signal %j', code, signal);
    // Close connection or do whatever else ...
  });
  // Ignore stderr
  stream.stderr.resume();
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM