首页 > 解决方案 > 如何在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()

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

标签: pythonpython-3.xsockets

解决方案


推荐阅读