简体   繁体   中英

Check what files are present in remote directory with grunt

I'm looking for a way to check which files are present in a remote directory i want to access via ssh or similar and write the filenames into an array.

So far I had no luck. unix rsync has an -n flag which can print every file which is present at the destinated location, but I don't get how to use the rsync-output in grunt.

Here's how you might do it via sftp with ssh2 :

var SSH2 = require('ssh2');

var conn = new SSH2();
conn.on('ready', function() {
  conn.sftp(function(err, sftp) {
    if (err) throw err;
    sftp.readdir('/tmp', function(err, list) {
      if (err) throw err;
      console.dir(list);
      conn.end();
    });
  });
}).connect({
  host: '192.168.100.100',
  port: 22,
  username: 'frylock',
  // password: 'foobarbaz',
  privateKey: require('fs').readFileSync('/here/is/my/key')
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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