I am using sockets to transfer a file over LAN. There are 2 scripts, the server opens a listens for connection and the client is run on another machine. I always make sure the server is run first. The strange thing is that if the the server script is double-clicked and executed (run in a console with title %Python path%python.exe) the output file saved on the server is truncated. It works just fine if you open the server script in IDLE and then run it. The client script can be run in either way, it still works. You could  try using any arbitrary file to test this behaviour after changing the file name in both the scripts.<br>
<br>==========================================================<br># file receiver<br># work in progress<br><br>import socket<br><br>s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)<br>HOST = '192.168.1.17'<br>
PORT = 31400<br><br>s.bind((HOST, PORT))<br>s.listen(3)<br>conn, addr = s.accept()<br>print 'conn at address',addr<br>conn.send('READY')<br>f = open('C:\\Documents and Settings\\USER\\Desktop\\test.pdf','wb')<br>
fsize=int(conn.recv(8))<br>print 'File size',fsize<br>f.write(conn.recv(fsize))<br>f.close()<br>conn.close()<br>s.close()<br><br>raw_input('Press any key to exit')<br><br><br>===========================================================<br>
<br># file sender !!!<br># Work in progress<br><br>import socket, os<br>from stat import ST_SIZE<br><br>    <br>HOST = '192.168.1.17'<br>PORT = 31400              # Arbitrary non-privileged port<br><br>s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)<br>
<br>s.connect((HOST,PORT))<br>if s.recv(5)!='READY':<br>    raw_input('Unable to connect \n\n Press any key to exit ...')<br>    s.close()<br>    exit()<br><br>f=open('C:\\Documents and Settings\\USER\\Desktop\\t.pdf', 'rb')<br>
fsize=os.stat(<a href="http://f.name">f.name</a>)[ST_SIZE]<br><br>s.send(str(fsize))<br>s.send(f.read())<br><br>s.close()<br>f.close()<br><br>===========================================================<br><br>Thanks for reading!!<br>
<br>Best regards,<br>Ferdi<br>