我希望我的应用程序能够自我更新,这是我已经尝试过的。
import nettell, ftpfm, os, shutil
def downupg():
# DOWNLOADING UPDATES
try:
if nettell.tell() == True:
ftpfm.retrive()
shutil.copy2('C:\\Program Files\\myapp\\update\\update.exe', 'C:\\Program Files\\myapp\\myrunningapp.exe')
except Exception, ex:
print str(ex)
#myrunningapp.exe is the exe file which download update and overwrite itself
#update.exe is the downloaded update file
其中 nettell 检查是否有网络连接并且包含
#!C:\python27\python.exe
#Python network module
import socket
def tell():
try:
if len(socket.gethostbyname('www.google.com')) != 0:
return True
except Exception, e:
return False
tell()
和 ftpfm 包含
import ftplib
import os
path = '/myappupdates'
filename = 'update.exe'
def retrive():
ftp = ftplib.FTP("ftp.myftpserver.com")
ftp.login("myusername", "mypassword")
ftp.cwd(path)
ftp.retrbinary("RETR %s" % filename,open('C:\\Program Files\\myapp\\update'+'\\'+filename, 'wb').write)
ftp.quit()
nettell和ftpfm没有任何问题,除了在尝试将新内容从(C:\ Program Files \ myapp \ update \ update.exe)复制到正在运行的exe文件时获得权限被拒绝异常( C:\ Program Files \ myapp \ myrunningapp.exe)并且得到了这个。
[Errno 13] Permission denied: 'C:\\Program Files\\myapp\\myrunningapp.exe'
我试图从互联网上找到答案,我得到了 this 这对我没有帮助。有什么方法可以从我自己内部更新我的应用程序。?