python 拷贝服务器文件夹,通过Python服务器复制到本地文件,远程,下,的

使用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()

参考文章: