python arcpy检索ftp中的文件

import ftplib
import os
import socket

HOST = ‘ftp.nifc.gov’
DIRN = ‘/Incident_Specific_Data/2012 HISTORIC/ROCKY_MTN/Arapaho/GIS/20120629’
FILE = ‘20120629_0600_Arapaho_PIO_0629_8x11_land.pdf’

try:
    f = ftplib.FTP(HOST)
except (socket.error, socket.gaierror), e:
    print(‘ERROR: cannot reach “%s”‘ % HOST)
print(‘*** Connected to host “%s”‘ % HOST)

try:
    f.login()
except ftplib.error_perm:
    print(‘ERROR: cannot login anonymously’)
    f.quit()
print(‘*** Logged in as “anonymous”‘)

try:
    f.cwd(DIRN)
except ftplib.error_perm:
    print(‘ERROR: cannot CD to “%s”‘ % DIRN)
    f.quit()
print(‘*** Changed to “%s” folder’ % DIRN)

try:
    f.retrbinary(‘RETR %s’ % FILE,
          open(FILE, ‘wb’).write)
except ftplib.error_perm:
    print(‘ERROR: cannot read file “%s”‘ % FILE)
    os.unlink(FILE)
else:
    print(‘*** Downloaded “%s” to CWD’ % FILE)
f.quit()

转载自:https://blog.csdn.net/A873054267/article/details/86007451

You may also like...