Python中的递归SFTP listdir? [英] Recursive SFTP listdir in Python?

查看:74
本文介绍了Python中的递归SFTP listdir?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要递归列出一个包含大量子目录(超过 16,000 个)的目录的内容.

I need to recursively list the content of a directory that contains a lot of subdirectories (more than 16,000).

我目前正在使用 Paramiko 的 SFTP 客户端,它没有t 提供任何递归 listdir 功能.所以我必须首先在父文件夹上运行 listdir,然后为每个(许多,许多)子目录运行另一个 listdir.运行时间太长.

I am currently using Paramiko's SFTP client, which doesn't offer any recursive listdir functionality. So I have to first run listdir on the parent folder, and then another listdir for each of the (many, many) subdirectories. It takes too long to run.

有没有办法在单个 SFTP 调用中运行递归 listdir?我不限于 Paramiko 包,它只是我们当前使用的包.

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 的 ssh.exec_command('ls -R <path>')(它只会返回错误消息).

I cannot use Paramiko's ssh.exec_command('ls -R <path>') due to local administrative restrictions (it would just return an error message).

推荐答案

所以我必须首先在父文件夹上运行 listdir,然后为每个(许多,许多)子目录运行另一个 listdir.

So I have to first run listdir on the parent folder, and then another listdir for each of the (many, many) subdirectories.

这是正确的方法.

有关实现的示例,请参阅
Linux 中的 Python pysftp get_r 在 Linux 上运行良好,但在 Windows 上不运行

For an example of an implementation, see
Python pysftp get_r from Linux works fine on Linux but not on Windows

有没有办法在单个 SFTP 调用中运行递归 listdir?我不限于 Paramiko 包,它只是我们当前使用的包.

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 协议本身没有任何方法来检索递归列表.并不是说其他​​类似的协议(如 FTP)通常具有这样的功能,所以这并不是真正的限制.

No. That's not limitation of Paramiko. SFTP protocol itself does not have any way to retrieve recursive listing. Not that other similar protocols (like FTP) have such functionality commonly, so it's not really a limitation.

这篇关于Python中的递归SFTP listdir?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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