前提:
1.samba共享文件
2.开启guest用户
3.共享文件权限设置正确,至少可读
def open_file(filename,path):
#filename:本地文件名称,C:/TEMP是我预设的下载后保存地址,可以自行修改
# path:远程服务器的路径
if os.chdir('C:/TEMP')==0:
os.mkdir('C:/TEMP')
if(os.path.exists(os.path.join('C:/TEMP',filename))!=1):
try:
print(os.path.join(path,filename))
with open(os.path.join(path,filename), 'rb') as f:
temp = f.read()
with open(os.path.join('C:/TEMP',filename), 'wb') as d:
d.write(temp)
except Exception as e:
print(e)
try:
os.startfile(os.path.join('C:/TEMP',filename))
except Exception as e:
print(e)
网友评论