[英]How to list all subdirectory using nodeJS SFTP client?
Amusing node JS ssh2-sftp-client.有趣的节点 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 https://www.npmjs.com/package/ssh2-sftp-client
The above code returns only the directories in the given path but not its subdirectories.上面的代码只返回给定路径中的目录,而不返回其子目录。
why are you using username/ password?你为什么使用用户名/密码? sftp is supposed to use ssh keys.
sftp 应该使用 ssh 密钥。 once the keys are shared, you dont need password.. you should be able to connect with the username.
密钥共享后,您不需要密码..您应该能够使用用户名进行连接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.