使用python进行远程到远程的大文件复制



我正在开发别人的Python脚本,该脚本在两个网络位置之间传输大文件(700mb以上(。脚本当前使用os.rename和shutil来复制这些文件。我是python的新手,但我知道这是将文件从位置a复制到我的本地Windows机器,然后复制到位置b。这相当慢,我已经开始寻找一种使复制更快的方法,我认为这将不涉及复制到本地机器,而是直接在位置a和b之间复制。

有人知道如何用蟒蛇的方式做这件事吗?

sendfile.py=(connect\socket(

import os
import socket
total = []
directory = "C:\folder\"
files = os.listdir(directory)
for file in files:
sock = socket.socket()
host = "192.168.1.111"
port = 667
sock.connect((host, port))
total += file.split(',')
sock.send(str.encode(file))
file = str.encode(directory + file)
with open(file, "rb") as file:
data = file.read(1024)
resp = sock.recv(1024)
if resp == b'Wainting file':
file_size = os.path.getsize(arquivo)
sock.send(bytes(str(file_size), 'utf-8'))
if resposta == b'Waiting...':
while data:
sock.send(data)
data = file.read(1024)
if not data:
sock.close()
if total == files:
print(total)

revice.py=(绑定/套接字(

import socket
sock = socket.socket()
host = '192.168.1.111'
port = 667
sock.bind((host, port))
sock.listen(10)
total = []
while True:
conn, addr = socket.accept()
directory = "C:\folder\to_recive\"
data = conn.recv(1024)
while data == b'':
conn.close()
conn, addr = sock.accept()
data = conn.recv(1024)
total += data.decode().split(',')
name_file = total[-1]
with open(f"{directory}{name_file}", "wb") as file:
conn.send(b"Waiting file")
data = conn.recv(1024)
size = data.decode('utf-8')
file_size = int(size)
if file_size != 0:
conn.send(b'Waiting...')
print("HOST <--> " + addr[0] + f" Download {name_file} - {size} kb")
while data:
data = conn.recv(1024)
file.write(data)

相关内容

  • 没有找到相关文章

最新更新