I am working on a program that backs up files like OneDrive or iCloud.
I made everything work but when I send a file trough the sockets it just gets stuck until I close the connection.
Here is the code sample:
The client:
def UpdateFileOnServer(file):
print("[!] Uploading file to server: ",file)
with open(clientFolder+file,"rb") as f:
s.sendall(file.encode())
file = f.read()
s.sendall(file)
print("[!] File has been sent.")
The server:
with open(fileLocation,"wb") as f:
print("[!] File recieved! Downloading...")
while True:
data = conn.recv(4096)
if not data:f.close();break
f.write(data)
So to summarize again:
- The client sends the file and says that it has been sent.
- The server receives about 90% of the file and indefinitely hangs until I CTRL+C the client
- When I do that the server finishes the file transfer and the file is successfully received.