Python/file_transfer/receive_file.py

24 lines
656 B
Python
Raw Normal View History

2019-10-05 05:14:13 +00:00
if __name__ == "__main__":
import socket # Import socket module
sock = socket.socket() # Create a socket object
host = socket.gethostname() # Get local machine name
port = 12312
sock.connect((host, port))
2019-10-05 05:14:13 +00:00
sock.send(b"Hello server!")
2019-10-05 05:14:13 +00:00
with open("Received_file", "wb") as out_file:
print("File opened")
print("Receiving data...")
while True:
data = sock.recv(1024)
print(f"{data = }")
if not data:
break
out_file.write(data) # Write data to a file
2019-10-05 05:14:13 +00:00
print("Successfully got the file")
sock.close()
2019-10-05 05:14:13 +00:00
print("Connection closed")