localpath = 'U:\\'
utime = sftp.stat("/TestBTEC/").st_mtime
last_modified = datetime.fromtimestamp(utime)
if (datetime.now()-last_modified)<=timedelta(hours=24):
sftp.get(last_modified, localpath)
Run Code Online (Sandbox Code Playgroud)
我收到以下异常错误:异常:datetime.datetime(2012,2,15,9,4,58)类型的未知类型
我正在尝试编写一个基本程序,它遍历目录中的文件并检查在最后xxxxxx中修改的文件.Unfortunatley datetime不允许我迭代到int.
file_list_attr = sftp.listdir_attr('/Path')
for f in file_list_attr:
print "name=%s, modified date=%s, size=%s" % (f.filename, f.st_mtime,f.st_size)
mt = f.st_mtime
now= dt.datetime.now()
delta = dt.timedelta(minutes=2120)
while mt > dt.datetime.now() - delta:
#while f.st_mtime == now-dt.timedelta(days=1):
print 'You have something here'
else:
print 'nada'
Run Code Online (Sandbox Code Playgroud)