使用Python拷贝windown共享目录下的文件
1、先通过net use命令获取共享目录访问权限
2、使用xcopy命令进行文件拷贝到本地目录
代码如下
import os
share_user='user'
share_password='password'
share_file_host='\\\\192.168.1.24'
share_file_path='\\\\192.168.1.24\\Git\\test_share_file.txt'
target_file_path='d:\\test777'
def copy_share_file():
permission_cmd=f'net use {share_file_host} {share_user} /user:{share_password}'
print(permission_cmd)
permission_result=os.popen(permission_cmd)
print(permission_result.read())
copy_cmd=f'xcopy /y {share_file_path} {target_file_path}'
print(copy_cmd)
copy_result=os.popen(copy_cmd)
print(copy_result.read())
if __name__ == '__main__':
copy_share_file()
参考文章:
https://blog.csdn.net/Gretchen_Grundler/article/details/79458770
https://www.cnblogs.com/lx823706/p/5976546.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)