Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Remote File Transfer- Error
#1
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!
Larz60+ write Jan-06-2021, 10:56 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Links are frowned upon.
Reply
#2
#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')
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  file transfer via python SFTP SCP mg24 3 3,009 Sep-15-2022, 04:20 AM
Last Post: mg24
  Multithreaded file transfer from multiple volumes skoobi 2 1,150 Jul-28-2022, 07:52 AM
Last Post: skoobi
Question resume file transfer onran 0 1,645 Jan-27-2021, 02:16 PM
Last Post: onran
  code to read files in folders and transfer the file name, type, date created to excel Divya577 0 1,871 Dec-06-2020, 04:14 PM
Last Post: Divya577
  DNP3 file transfer with python Aussie 0 1,461 Sep-01-2020, 10:45 PM
Last Post: Aussie
  Splitting the audio file into smaller packets before transfer using UDP protocol in p MuhammadAli152 0 3,739 May-15-2020, 03:01 PM
Last Post: MuhammadAli152
  How to stop Xmodem after bin file transfer was finished shaya2103 0 2,523 Nov-27-2019, 04:33 PM
Last Post: shaya2103
  Read a remote text file Sandy7771989 1 7,023 Jul-18-2019, 06:55 PM
Last Post: ndc85430
  How to run python code in Java using remote SSH without py file using streams in Java varanasipavankumar 0 2,546 Apr-07-2019, 06:13 PM
Last Post: varanasipavankumar
  How to transfer a music file, from "uploads" directory into my project sylas 15 8,827 Sep-10-2017, 09:16 PM
Last Post: sylas

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020