Reputation: 21971
from six.moves.urllib.request import urlopen, urlretrieve, urlrequest
conn = urlopen('ftp://ftp.cdc.noaa.gov/Datasets/ncep.reanalysis.dailyavgs/surface/lftx.sfc.2017.nc', timeout=20)
last_modified = conn.headers['last-modified']
Following How can I get the last-modified time with python3 urllib? I want to get last modification date of a file on a FTP server. However, with the code above, last-modified
is None
. Any suggestions? I want solution to work on both python 2 and python 3
Upvotes: 2
Views: 3013
Reputation: 202282
The documentation of urlopen
does not claim that it returns last-modified
for FTP URLs.
Note that there are no headers in FTP protocol. The urlopen
just fakes few HTTP-like headers for some kind of compatibility of the interface across protocols.
To retrieve timestamp using FTP, use the ftplib. See How to get FTP file's modify time using Python ftplib.
Upvotes: 1