如何通过给定名称仅获取 FTP 目录中的那些?

how to get only those in an FTP directory by a given name?

我只想下载一个文件组。 在这种情况下,我想从 NOAA 服务器下载湿度数据 怎么只搜索相对湿度文件?

from ftplib import FTP
from datetime import datetime


print('Get Conection in NOAA server...')

start = datetime.now()
ftp = FTP('ftp.cdc.noaa.gov')
ftp.login()
ftp.cwd('Datasets/ncep.reanalysis.dailyavgs/pressure/')
print('Done!')

# Get All Files
files = ftp.nlst()
print(files)
# Print out the files

for file in files:
    print("Downloading..." + file)
    ftp.retrbinary("RETR " + file ,open("D:\Dados_Eventos_Extremos\Precipitacao\" + file, 'wb').write)

print('Close Conection')
ftp.close()

end = datetime.now()
diff = start - end
print('Download Files in ' + str(diff.seconds) + 's')


# My output is this!
hgt.2017.nc
hgt.2018.nc
hgt.2019.nc
hgt.2020.nc
omega.1948.nc
omega.1949.nc
omega.1950.nc
omega.1951.nc
omega.1952.nc
omega.1953.nc
omega.1954.nc
omega.1955.nc
omega.1956.nc
omega.2020.nc
rhum.1948.nc
rhum.1949.nc
rhum.1950.nc
rhum.1951.nc
rhum.1952.nc
rhum.1953.nc
rhum.1954.nc
rhum.1955.nc
rhum.1956.nc
rhum.1957.nc
rhum.1958.nc
rhum.1959.nc
rhum.1960.nc

我只想下载 'rhum' 个文件

谁能帮帮我,请给我一些想法。

对于 most FTP servers,这将完成:

files = ftp.nlst("*rhum*")

(虽然是非标准方式)