def main():
os.makedirs(localstor, exist_ok=True)
with ProcessPoolExecutor() as executor:
with ftputil.FTPHost('files.dlink.com.au', 'anonymous', '') as host:
with open('au_dlink_ftp_filelist.csv', 'w') as fout:
cw = csv.writer(fout)
cw.writerow(["ftpurl", "fsize", "fdate", "file_sha1", "file_md5"])
models = host.listdir('/Products/')
for model in models:
if not host.path.isdir('/Products/%(model)s'%locals()):
continue
if not re.match(r'[A-Z]+', model, re.I):
continue
revs = host.listdir('/Products/%(model)s/'%locals())
for rev in revs:
if not re.match(r'REV_\w+', rev, re.I):
continue
try:
fwitems = host.listdir('/Products/%(model)s/%(rev)s/Firmware/'%locals())
except:
continue
try:
for fwitem in fwitems:
print('visiting /Products/%(model)s/%(rev)s/Firmware/%(fwitem)s/'%locals())
try:
fw_files = host.path.listdir('/Products/%(model)s/%(rev)s/Firmware/%(fwitem)s/'%locals())
for fw_file in fw_files:
host.keep_alive()
executor.submit(download, '/Products/%(model)s/%(rev)s/Firmware/%(fwitem)s/%(fw_file)s'%locals())
except:
if host.path.isfile('/Products/%(model)s/%(rev)s/Firmware/%(fwitem)s'%locals()):
executor.submit(download,'/Products/%(model)s/%(rev)s/Firmware/%(fwitem)s'%locals())
except Exception as ex:
print(ex)
评论列表
文章目录