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')
});