【发布时间】:2010-08-21 01:57:05
【问题描述】:
我需要编写一个遍历 FTP 服务器上的文件夹的 python 脚本。
ftp文件夹中的文件:
#get it
#do something untoward with it
欢迎提供片段和非车轮改造建议。
【问题讨论】:
标签: python ftp download directory traversal
我需要编写一个遍历 FTP 服务器上的文件夹的 python 脚本。
#get it
#do something untoward with it
欢迎提供片段和非车轮改造建议。
【问题讨论】:
标签: python ftp download directory traversal
ftputil 是您要查找的第三方模块:
ftputil 是一个高级 FTP 客户端 Python 编程库 语。 ftputil 实现了一个虚拟 用于访问 FTP 服务器的文件系统, 也就是说,它可以生成类似文件的 远程文件的对象。图书馆 支持许多类似的功能 os、os.path 和 shutil 中的那些 模块。
注意例如 sn-p here:
# download some files from the login directory
host = ftputil.FTPHost('ftp.domain.com', 'user', 'secret')
names = host.listdir(host.curdir)
for name in names:
if host.path.isfile(name):
host.download(name, name, 'b') # remote, local, binary mode
ftputil 是纯 Python,非常稳定,并且在 pypi 上非常受欢迎(用户对其评分为 9,我认为这是 pypi 规模的最大值)。有什么不喜欢的?-)
【讨论】:
ftputil 而不是stdlib 的ftplib 会很好(EG,易于使用)。