编程语言
首页 > 编程语言> > python – 通过ftp创建文件的日期

python – 通过ftp创建文件的日期

作者:互联网

美好的一天!

如何通过ftp获取文件的创建日期?
我使用web2py,python,ftplib和filezilla作为ftp服务器.我可以通过f.sendcmd(‘MDTM’文件名)获取修改日期.

有什么建议?谢谢!

解决方法:

您有类似以下内容:

connection = ftplib.FTP(**ftpCredentials)
modifiedTime = connection.sendcmd('MDTM ' + fileName)
# successful response: '213 20120222090254'

要解释修改时间,您应该执行以下操作:

from datetime import datetime

print datetime.strptime(modifiedTime[4:], "%Y%m%d%H%M%S").strftime("%d %B %Y %H:%M:%S")
# prints something like 01 January 1970 09:30:01

资料来源:this blog post @ http://alexharvey.eu/code/python/get-a-files-last-modified-datetime-using-python/

标签:web2py,python,ftplib,filezilla
来源: https://codeday.me/bug/20190728/1564798.html