循环脚本并每5分钟上传一个文件

时间:2017-04-21 10:09:27

标签: python ftp upload

我已创建此脚本以使用python上传文本文件,但我现在想要修改此脚本以每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()

1 个答案:

答案 0 :(得分:0)

Python有sched module用于事件安排。

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()