-1

I want to get the contents of a folder and call this command -> "sftp.list (...)".

But this will return a Promise object. How can I get to the name of this content??

I've attached my code below, but I always just get ALL INFOS back.

var a = sftp.list(remoteFilename);
a.then(function(result){
   console.log(a);
});


OUTPUT:
  { type: '-',
    name: '14335.JSON',
    size: 482369,
    modifyTime: 1549637889000,
    accessTime: 1549541207000,
    rights: { user: 'rw', group: 'rw', other: 'rw' },
    owner: 98438,
    group: 840223400513 } ]

But i want only the name from the files.

gegner1111
  • 25
  • 7
  • 4
    Possible duplicate of [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – adiga Feb 13 '19 at 12:22
  • You wait for it. There's no way to synchronously access it. – Bergi Feb 13 '19 at 12:46

1 Answers1

0

Your code is not correct, to return the result of a Promise, you must use return as below:

var a = new Promise(function(res, rej){
                    // return promise
                    return sftp.list(remoteFilename);
                }).then((result) => {console.log(result); // your result here});

If you need to get the return value for a, use await

Juky
  • 247
  • 1
  • 9