python - Python 中的递归 SFTP listdir?

标签 python sftp paramiko listdir

我需要递归列出包含很多子目录(超过 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 another listdir 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/

相关文章:

python - 从字符串执行命令并对其计时

python - 项目分配 Tensorflow 2.0 - TypeError : 'tensorflow.python.framework.ops.EagerTensor' object does not support item assignment

Python sftp 与 paramiko 错误

python - 如何使用 Python 的 Paramiko 模块 ssh 到需要两次密码身份验证的服务器?

python - "TypeError: ' 模块 ' object is not callable"使用 beeswarm 时出错

Python FTP : "TimeoutError: [Errno 110] Connection timed out" but I can connect with sftp in terminal

delphi - Delphi 2010 中的 SSH 上的 FTP (SFTP)

python - 在Python中将密码发送到sftp子进程

python - Paramiko:将 ssh session 嵌套到另一台机器,同时保留 paramiko 功能(ProxyJump)

Python 类似队列的数据结构