如何使用nodeJS SFTP客户端列出所有子目录? [英] How to list all subdirectory using nodeJS SFTP client?

查看:96
本文介绍了如何使用nodeJS SFTP客户端列出所有子目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

娱乐节点JS ssh2-sftp-client.我想列出给定路径中的所有目录及其子目录吗?

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.

推荐答案

为什么要使用用户名/密码? sftp应该使用ssh密钥.密钥共享后,您就不需要密码了.您应该可以使用用户名进行连接.

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.

这篇关于如何使用nodeJS SFTP客户端列出所有子目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆