file transfer code python
<p>I found the code here: <a href="http://stackoverflow.com/questions/9382045/send-a-file-through-sockets-in-python">Send a file through sockets in python</a> (the selected answer)</p>

<p>But I will jut post it here again..</p>

<pre><code>server.py
import socket
import sys
s = socket.socket()
s.bind(("localhost",9999))
s.listen(10) 
while True:
    sc, address = s.accept()

    print address
    i=1
    f = open('file_'+ str(i)+".txt",'wb') #open in binary
    i=i+1
    while (True):       
        l = sc.recv(1024)
        while (l):
            print l #&lt;--- i can see the data here
            f.write(l) #&lt;--- here is the issue.. the file is blank
            l = sc.recv(1024)
    f.close()

    sc.close()

s.close()



client.py

import socket
import sys

s = socket.socket()
s.connect(("localhost",9999))
f=open ("test.txt", "rb") 
l = f.read(1024)
while (l):
    print l
    s.send(l)
    l = f.read(1024)
s.close()
</code></pre>

<p>On server code, the print l line prints the file contents..so that means that content is being transferred..
but then the file is empty??</p>

<p>what am i missing?
thanks</p>
