How to list all subdirectory using nodeJS SFTP client?

拥有回忆 提交于 2020-03-02 11:59:06

问题


Amusing node JS ssh2-sftp-client. I want to the list all the directory and its subdirectories in a given path?

 let sftp = new ssh2SftpClient();
console.log(sftp);
sftp.connect({
    host: 'xx.xxx.xxx.xxx',
    port: '22',
    username: 'centos',
    privateKey: require('fs').readFileSync('/home/myHome/aws_int.ppk')
}).then(() => {
    return sftp.list('/home/centos/myHome');
}).then((data) => {
    console.log('the data info : ' + data);
    for(i = 0; i < data.length; i++) {
        console.log(data);
        console.log(data[i].name);
    }
}).catch((err) => {
    console.log('catch error : ' + err);
}).catch(() => {
    console.log('catch error : ' + err);
});

https://www.npmjs.com/package/ssh2-sftp-client

The above code returns only the directories in the given path but not its subdirectories.


回答1:


why are you using username/ password? sftp is supposed to use ssh keys. once the keys are shared, you dont need password.. you should be able to connect with the username.



来源:https://stackoverflow.com/questions/48589154/how-to-list-all-subdirectory-using-nodejs-sftp-client

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!