import os
import shutil
import re
def repalce_drive(path,virtual_drive):
# 把盘符替换为虚拟盘符
res = re.match('(\w{1})(:.*?)', path)
drive = res.group(1)
start = res.start(1)
end = res.end(1)
return drive,''.join([path[:start],virtual_drive,path[end:]])
def windows2windows(ip,user,password,srcpath,dstpath):
'''
从远程电脑拿到本机
'''
# 共享盘的盘符
virtual_drives = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
# 倒序
virtual_drives = virtual_drives[::-1]
flag = False
for virtual_drive in virtual_drives:
# 虚拟盘如果本机有重复的,则重新换
try:
drive,virtual_srcpath = repalce_drive(srcpath, virtual_drive)
# 建立共享盘
cmd = r'net use {}: \\{}\{}$ /user:{} {} /PERSISTENT:YES'.format(virtual_drive,ip,drive,user,password)
os.system(cmd)
# 复制目录
shutil.copytree(virtual_srcpath, dstpath, True)
# 清除共享盘
cmd = r'net use {}: /del'.format(virtual_drive)
os.system(cmd)
flag = True
except:
pass
if flag:
break
if __name__ == '__main__':
# 远程电脑的相关信息
src_ip = '192.168.1.1'
src_user = 'Administrator'
src_password = '12345'
src_path = 'f:/test'
# 存入本机的地址信息
dst_path = 'D:/test'
windows2windows(src_ip, src_user, src_password, src_path, dst_path)
windows文件远程传输
最新推荐文章于 2024-09-13 16:29:28 发布