python 删除文件 通配符,Python:如何获取文件列表并在FTP目录中使用通配符?

I'm new to python. I want to access baseURL and eventually get a list of files in one of the sub-directories so I can download/unzip this file. The specific file extension can change so I'm hoping to find a match to the file by just the date (yyyymmdd).

baseURL = 'ftp://prism.nacse.org'

Thanks in advance for your guidance!

My code so far is:

variables = ['ppt', 'tmax', 'tmin']

nvars = len(variables)

baseURL = 'ftp://prism.nacse.org/daily/'

stDateNum = date.toordinal(date(1981,1,1)) # Year, Month, Day

edDateNum = date.toordinal(date(2017,4,22))

dates = list(range(stDateNum,edDateNum+1))

ndates = len(dates)

for v in range(0,nvars):

for d in range(0,ndates):

tmpdate = date.fromordinal(dates[d]).strftime('%Y%m%d') #yyyymmdd

tmpYR = date.fromordinal(dates[d]).strftime('%Y') #yyyy

totalpath = baseURL + variables[v] + '/' + tmpYR + '/*_' + tmpdate + '_bil.zip'

解决方案

You could use Python ftplib, https://docs.python.org/3/library/ftplib.html, as a ftp client. I don't think wildcard downloads are support, so you'd have to do something along the lines of...

Login to the FTP server

Navigate to the desired directory

Get a listing of the files, iterate thorough the files and match according to the desired file format

Download desired files

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值