前提:
1.samba共享文件
2.開啟guest用戶
3.共享文件權(quán)限設(shè)置正確,至少可讀
def open_file(filename,path):
#filename:本地文件名稱,C:/TEMP是我預(yù)設(shè)的下載后保存地址,可以自行修改
# path:遠(yuǎn)程服務(wù)器的路徑
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)
last_write_time_human=str(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(i.last_write_time))) #將smb時(shí)間改為人類可讀的時(shí)間