我需要递归列出包含很多子目录(超过 16,000 个)的目录的内容。
我目前正在使用 Paramiko's SFTP client ,它不提供任何递归 listdir
功能。所以我必须先运行listdir
在父文件夹上,然后是另一个 listdir
对于每个(很多很多)子目录。运行时间太长。
有没有办法运行递归listdir
在单个 SFTP 调用中?我不限于 Paramiko 包,它只是我们当前正在使用的包。
我无法使用Paramiko的ssh.exec_command('ls -R <path>')
由于本地管理限制(它只会返回错误消息)。
最佳答案
So I have to first run
listdir
on the parent folder, and then anotherlistdir
for each of the (many, many) subdirectories.
这才是正确的做法。
有关实现的示例,请参阅
Python pysftp get_r from Linux works fine on Linux but not on Windows
Is there any way to run the recursive
listdir
in a single SFTP call? I'm not limited to the Paramiko package, it's just the package that we're currently using.
没有。这不是Paramiko 的限制。 SFTP 协议(protocol)本身没有任何方法来检索递归列表。并非其他类似协议(protocol) ( like FTP ) 通常具有此类功能,因此这并不是真正的限制。
关于python - Python 中的递归 SFTP listdir?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48368690/