I want to do a simple file transfer program that transfer file from client to server. The server sends a path to the client and the client send the file to the server. But I don't know how to create the file in the server part. In fact, I send all the file in binary mode but after that I receive every bytes in the server mode I don't know how to make the file from the bytes that I receive .
Client Part
sock = 0
path = " "
def open_socket():
global sock
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(("localhost", 9000))
def transfer_file(path):
f = open(path, "rb").read()
sock.send(f)
def main():
open_socket()
path = sock.recv(1024)
if __name__ == "__main__":
main()
Server Part
def open_connection():
global client
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(("0.0.0.0", 9000))
sock.listen(1)
client, address = sock.accept()
def file_transfer():
path = raw_input("Enter path of file: ")
client.send(path)
while True:
file_from_client = client.recv(1024)
def main():
open_connection()
file_transfer()
if __name__ == "__main__":
main()
Thanks you !