prakash jp wrote:
Hi all,
On generating log file on remote systems(say client), I want to transfer them to the Network Admins(say Server) Computer. In doing so all the contents of the log file r not transfered, only part of the file. I appreciate ur help, here is the pre-existant code: file sender !!!------client:
# Work in progress
import socket, os
from stat import ST_SIZE
HOST = '192.168.3.136'
PORT = 31400              # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST,PORT))
if s.recv(5)!='READY':
    raw_input('Unable to connect \n\n Press any key to exit ...')
    s.close()
    exit()
f=open(r'C:\\Python25\src\log.txt', 'rb')
fsize=os.stat(f.name <http://f.name>)[ST_SIZE]
#s.sendd(str(fsize))
s.send(str(fsize).zfill(8))
s.send(f.read())

You might want to try sendall() instead of send(). send() doesn't
guarantee to send all the data, but instead returns the number of bytes
that it did actually send. sendall(), on the other hand, will keep
going until all of the data is sent.

s.close()
f.close()
##################################################
file receiver : server
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
HOST = '192.168.3.136'
PORT = 31400
s.bind((HOST, PORT))
s.listen(3)
conn, addr = s.accept()
print 'conn at address',addr
conn.send('READY')
f = open(r'C:\\Python25\dest\dest.txt','wb')
fsize=int(conn.recv(8))
print 'File size',fsize
f.write(conn.recv(fsize))
f.close()
conn.close()
s.close()
################################################### Regards
Prakash


------------------------------------------------------------------------

--
http://mail.python.org/mailman/listinfo/python-list

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to