我无法在python中的文件上设置ctime/mtime.首先,我通过ftp获取文件的原始时间戳
我唯一想要的是使用ftplib在我下载的文件上保留原始时间戳.
def getFileTime(ftp,name):
try :
modifiedTime = ftp.sendcmd('MDTM ' + name)
filtid = datetime.strptime(modifiedTime[4:], "%Y%m%d%H%M%S").strftime("%d %B %Y %H:%M:%S")
return filtid
except :
return False
Run Code Online (Sandbox Code Playgroud)
然后我下载文件
def downloadFile(ftp, fileName) :
try:
ftp.retrbinary('RETR %s' % fileName,open(fileName, 'wb').write)
except ftplib.error_perm:
print 'ERROR: cannot read file "%s"' % fileName
os.unlink(fileName)
return False
else:
print '*** Downloaded "%s" to CWD' % fileName
return True
Run Code Online (Sandbox Code Playgroud)
我想将原始时间戳设置为下载的文件
def modifyTimestapToOriginal(fileName, orgTime):
#try:
os.utime(fileName, orgTime)
fileName.close()
# return True
# except:
# return False
Run Code Online (Sandbox Code Playgroud)
这就是我试图这样做的方式
ftp, files = …Run Code Online (Sandbox Code Playgroud)