[英]How to download a specific file type from all subdirectories of an FTP server?
I am trying to download all .laz
files from the FTP host gis.arkansas.gov
(more details here ). 我正在尝试从FTP主机gis.arkansas.gov
下载所有.laz
文件( 此处有更多详细信息)。 Looking at the ftplib
documentation, I see that I can list all of the directories in the FTP server: 查看ftplib
文档,我发现可以列出FTP服务器中的所有目录:
from ftplib import FTP
ftp = FTP('gis.arkansas.gov')
ftp.login()
ftp.cwd('Elevation')
ftp.retrlines('LIST')
Which yields the following: 结果如下:
>>> ftp.retrlines('LIST')
drwxr-xr-x 1 ftp ftp 0 May 30 09:24 AGFC_RAW
drwxr-xr-x 1 ftp ftp 0 May 30 09:24 AR State Parks
drwxr-xr-x 1 ftp ftp 0 May 30 09:24 Bayou Meto Lidar Phase I
drwxr-xr-x 1 ftp ftp 0 May 30 09:24 Bayou_Meto_Watershed
drwxr-xr-x 1 ftp ftp 0 May 30 09:24 Beaver_Lake
drwxr-xr-x 1 ftp ftp 0 May 30 09:24 Beaver_Tailwater
drwxr-xr-x 1 ftp ftp 0 May 30 09:24 Black_River
drwxr-xr-x 1 ftp ftp 0 May 30 09:24 Blue_Mountain
# ... And so on ...
How can I download all of the files with a .laz extension from each of these directories (some directories do not contain .laz files)? 如何从每个目录中下载所有扩展名为.laz的文件(某些目录不包含.laz文件)?
There's no magic. 没有魔术。
You have to: 你必须:
.laz
files, 过滤所有.laz
文件, retrbinary
for each. 为每个调用retrbinary
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.