Python Forum
Remote File Transfer- Error - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Remote File Transfer- Error (/thread-31842.html)



Remote File Transfer- Error - wonderboy - Jan-06-2021

I want to upload a file from my server (linux machine) to my client machine(Windows 10), however when i try to do that I'm only able to transfer a blank file to the clients machine but the file data is not transferred. Can someone please check my code below and tell me what's wrong with it.
#Client Code:
 elif command.lower() == "upload":
        file_name = s.recv(1024).decode()
        data2 = s.recv(1078000)
        new_file = open(file_name, "wb")
        while(data2):         
            new_file.write(data2)
            data2 = s.recv(1078000)
            new_file.close()
            print("Recieved File")
#Server Code:
    elif command.lower() == "upload":
        client_socket.send(command.encode())
        print("")
        file_path = input(str("Enter the file path to send: "))
        file_name = input(str("Enter the file NAME to send: "))
        client_socket.send(file_name.encode())       
        f = open(file_path, "rb")
        print('Sending file...')
        data = f.read(1078000)
        while(data):
                connectionSocket.send(data)
                data = f.read(1078000)
                f.close()
                print('Done sending')
Thanks!


RE: Remote File Transfer- Error - wonderboy - Jan-06-2021

#Client Code:
elif command.lower() == "upload":
        file_name = s.recv(1024).decode()
        data2 = s.recv(1078000)
        new_file = open(file_name, "wb")
        while(data2):         
            new_file.write(data2)
            data2 = s.recv(1078000)
            new_file.close()
            print("Recieved File")
#Server code:
 elif command.lower() == "upload":
        client_socket.send(command.encode())
        print("")
        file_path = input(str("Enter the file path to send: "))
        file_name = input(str("Enter the file NAME to send: "))
        client_socket.send(file_name.encode())       
        f = open(file_path, "rb")
        print('Sending file...')
        data = f.read(1078000)
        while(data):
                connectionSocket.send(data)
                data = f.read(1078000)
                f.close()
                print('Done sending')