I am creating a client server program on which client downloads server's files. it works fine in localhost, but the problem occurs in except localhost connection. I've tried googling but none of the solutions(from previously suggested to the same problem) works.
Here is my code:
def upload(sock): # server.py
filename = str(sock.recv(4096)).split(' end')[0]
if os.path.exists(filename):
sock.send('YES')
sock.send(str(os.path.getsize(filename)) + ' end')
foo = open(filename, 'rb')
upbytes = foo.read(4096)
sock.sendall(upbytes)
while upbytes != '':
upbytes = foo.read(4096)
sock.sendall(upbytes)
foo.close()
print "\tUpload Complete !"
else:
sock.send('NO')
def download(sock, filename): #client.py
sock.send(filename + ' end')
if sock.recv(4096) == 'YES':
filesize = int(str(sock.recv(4096)).split(' end')[0])
print filesize, 'filesize'
foo = open('downloaded_' + os.path.basename(filename), 'wb')
downbytes = sock.recv(4096)
foo.write(downbytes)
downlen = len(downbytes)
while downlen < filesize:
downbytes = sock.recv(4096)
if not downbytes:
break
foo.write(downbytes)
downlen += len(downbytes)
foo.close()
print 'filesize', filesize, 'downlen', downlen
print "\t\tDownload Complete !\n"
else:
print "\t\tFile not found ! <" + filename + '>'
I've tried different solutions but none of them worked!