2012-02-15 97 views
1
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) 

我收到以下異常錯誤修改時間: 例外:未知類型datetime.datetime(2012,2,15,9,4,58)型Paramiko。獲取文件通過

回答

2

試試:

from datetime import datetime, timedelta 
import stat 
import paramiko 

ssh = paramiko.SSHClient() 
... 
ssh.connect(host, **params) 
... 
sftp = ssh.open_sftp() 
... 
utime = sftp.stat(PATH_TO_REMOTE_FILE).st_mtime 
last_modified = datetime.fromtimestamp(utime) 
if (datetime.now()-last_modified)<=timedelta(hours=24): 
    do something with your file 
+0

我會嘗試應用這個。並且需要計算如何獲取多個文件(如果其中有多個文件已被修改) – user1086526 2012-02-15 14:25:52

+0

例外:datetime.datetime的未知類型(2012,2,15,9,4,58)type 我相信YearMonthDayHourMinute是標準 – user1086526 2012-02-15 15:42:30