I'm trying to load a CSV file to Amazon S3 with Python. I need to know CSV file's modification time. I'm using ftplib to connect FTP with Python (2.7).
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
MLST or MDTM
While you can retrieve a timestamp of an individual file over FTP with
MLST
orMDTM
commands, neither is supported by ftplib.Of course you can implement the
MLST
orMDTM
on your own usingFTP.voidcmd
.See:
A simple example for
MDTM
:MLSD
The only command explicitly supported by the ftplib library that can return standardized file timestamp is
MLSD
viaFTP.mlsd
method. Though its use makes sense only if you want to retrieve timestamps for more files.MLSD
modify
factYYYYMMDDHHMMSS[.sss]
For details, refer to RFC 3659, particularly the:
Note that times returned by
MLST
,MLSD
andMDTM
are in UTC (unless the server is broken). So you may need to correct them for your local timezone.Again, refer to RFC 3659 2.3. Times section:
LIST
If the FTP server does not support any of
MLST
,MLSD
andMDTM
, all you can do is to use an obsoleteLIST
command. That involves parsing a proprietary listing it returns.A common *nix listing is like:
With a listing like this, this code will do:
Finding the latest file
See also Python FTP get the most recent file by date.
When I want to change the file modification time, I use an FTP client on the console. Log on to a remote FTP ftp ftp.dic.com
change the access time, modification time, it's time to create a directory on 2005-01-01 12:30:00 somefile.txt
Complete example:
Please feel free to sit back and wish you a pleasant journey in time :)