在python中如何将文件夹从服务器复制到客户端

2024-06-14 09:39:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试将文件夹从服务器复制到客户端文件位于x目录下。想知道如何在服务器中设置文件路径吗

服务器端

filename = '/home/Desktop/features'
f = open(filename, 'rb')
while True:
    l = f.read(buff_size)
    while (l):
        self.sock.sendall(l)
        # print('Sent ',repr(l))
        l = f.read(buff_size)

    if not l:
        f.close()
        self.sock.close()
        break

客户端

with open('red_fi', 'rb') as f:
    print('file opened client ')
    time.sleep(3)

    a = True

    while a:
        print('receiving data...')
        data = s.recv(buff_size)
        # print('data=%s', (data))

        if not data:
            f.close()
            # time.sleep(3)
            print('file closed client')
            a = False
            break
        # write data to a file
        f.write(data)

    # time.sleep(2)
    print('Successfully received the file')
    print(id_list)
    s.close()

我希望功能文件夹从服务器复制到客户端


Tags: 文件服务器文件夹客户端closedatasizetime