简体   繁体   English

如何使用nodeJS SFTP客户端列出所有子目录?

[英]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.

相关问题 NodeJS ssh2-sftp-客户端 | 使用公钥和密码连接到 SFTP - NodeJS ssh2-sftp-client | connecting to SFTP using public key and a passphrase 如何使用 nodeJS 列出所有子目录和文件? - How to list all subdirectories and files using nodeJS? 如何使用Grunt压缩子文件夹/子目录中的所有JavaScript文件? - How to uglify all javascript files in subfolders/subdirectory using Grunt? 如何使用NodeJS下载pdf并将其发送到客户端? - how to download pdf using NodeJS and send it to the client? 在 ssh2-sftp-client 中使用 ssh 指纹 - Using ssh fingerprint in ssh2-sftp-client 如何使用nodejs检查SFtp上是否存在远程目录? - How do I check whether remote directory exist or not on SFtp using nodejs? gRPC NodeJS如何获取所有方法的列表 - gRPC NodeJS how to get list of all methods 我如何使用 Nodejs 列出 windows 和 mac OS 上所有已安装的驱动程序 - how can i list all the installed drivers on windows & mac OS using Nodejs 错误:所有配置的身份验证方法都失败,当连接到在 aws 上创建的 vsftpd 服务器时,使用 npm 模块 - ssh2-sftp-client - Error: All configured authentication methods failed , when connecting to vsftpd server created on aws , using npm module - ssh2-sftp-client 如何使用 NodeJS 删除 DocumentDB 中的所有文档? - How to delete all documents in DocumentDB using NodeJS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM