2017-04-21 44 views
-3

我已經創建了這個腳本來上傳一個帶有python的文本文件,但是現在我想要修改這個腳本來每5分鐘上傳一次這個文件。我怎樣才能做到這一點?循環一個腳本並每5分鐘上傳一個文件

import ftplib 
 
import win32api 
 
import os 
 

 
sftp = ftplib.FTP('ftp.microsoft.com','test','test') # Connect 
 
sftp.cwd("test") 
 

 
fp = open('test.txt','rb') # file to send 
 
sftp.storbinary('test.txt', fp) # Send the file 
 

 
fp.close() # Close file and FTP 
 
sftp.quit()

+0

使用cron http://www.thegeekstuff.com/2011/07/cron-every-5-minutes/ – Mateusz

回答

0

Python有schedmodule用於事件的調度。

import sched, time 
s = sched.scheduler(time.time, time.sleep) 
def do_something(sc): 
    print "Doing stuff..." 
    # scheduling calls 
    s.enter(300, 1, do_something, (sc,)) 

# initial call to function 
s.enter(60, 1, do_something, (s,)) # (delay, priority, action, argument) 
s.run() 
相關問題