gpt4 book ai didi

python - 用python遍历一个ftp文件夹

转载 作者:行者123 更新时间:2023-11-28 19:41:02 25 4
gpt4 key购买 nike

我需要编写一个遍历 FTP 服务器上的文件夹的 python 脚本。

ftp文件夹中的文件:

#get it
#do something untoward with it

欢迎提供片段和非轮子改造建议。

最佳答案

ftputil是您要查找的第三方模块:

ftputil is a high-level FTP client library for the Python programming language. ftputil implements a virtual file system for accessing FTP servers, that is, it can generate file-like objects for remote files. The library supports many functions similar to those in the os, os.path and shutil modules.

例如,注意片段 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 规模上的最高分)。有什么不喜欢的?-)

关于python - 用python遍历一个ftp文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3535936/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com