PYQT5学习与开发

PYTHON(2)从windows远程共享文件夹内下载文件

2019-08-21  本文已影响47人  弗兰克万岁

前提:

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)
上一篇下一篇

猜你喜欢

热点阅读