Sending A File From Local To Server Using Python - The Correct Way
Probably a simple question for those who used to play with socket module. But I didn't get to understand so far why I can't send a simple file. As far as I know there are four impo
Solution 1:
I'm not sure what your second while True
loop is for. Remove that, and it works as you expect:
import socket
import sys
s = socket.socket() # create the socket
s.bind(("localhost", 8081)) # bind
s.listen(10)
while True:
sc, address = s.accept()
print sc, address
f = open('logs_1.txt', 'wb+')
l = sc.recv(1024)
while l:
f.write(l)
l = sc.recv(1024)
f.close()
sc.close()
s.close()
Post a Comment for "Sending A File From Local To Server Using Python - The Correct Way"