0

我在将数据从客户端写入服务器端到 .xls、.php 或 .doc 文件时遇到问题。这是我的服务器端代码

amtOfFilesHeader = ""
while True:
    d = connectionSocket.recv(1)
    if d == '\n':
        break
    amtOfFilesHeader += d
amtOfFiles = int(amtOfFilesHeader.split()[-1])
while amtOfFiles > 0:
    header = ""
    while True:
        d = connectionSocket.recv(1)
        if d == '\n':
            break
        header += d

    filesize = int(header.split()[-1])
    # or search for the last space in header
    # and get a substring of header as filename
    filename = "".join(header.split()[1:-1])
    data = ""
    while filesize > 0:
        chunk = connectionSocket.recv(1) # or any amount of data
        filesize -= len(chunk)
        data += chunk
    file = open((server_side_folder+'/'+filename),'wb')
    file.write(data)
    file.close()
    amtOfFiles-=1

我不断收到错误,例如:

IOError: [Errno 2] No such file or directory: 'server_side/test.xls'

虽然我已经打开了要写入的文件。我在代码中做错了吗?

4

1 回答 1

0

我设法找到错误在哪里。事实证明,我的服务器和客户端线程的超时时间太短了。增加超时后,我可以读取 .xls、.php 和 .php 文件。

于 2013-03-19T14:39:43.283 回答