【发布时间】:2021-11-12 12:32:54
【问题描述】:
在问题here 中,我们学习了如何在python 中使用FTP 获取文件。答案是我的代码中的内容,也如下:
import shutil
import urllib.request as request
from contextlib import closing
with closing(request.urlopen('ftp://server/path/to/file')) as r:
with open('file', 'wb') as f:
shutil.copyfileobj(r, f)
我现在如何在本地保存这些文件?这个path/to/file 在嵌套目录中有一堆目录和文件。理想情况下,我想下载根目录并在其中包含所有文件和文件夹。
由于我是 Python 和 FTP 的新手,我不能 100% 确定我的问题是否尽可能清楚。请不要犹豫,在 cmets 中要求澄清,谢谢!
【问题讨论】:
标签: python python-3.x ftp shutil