2

I'm currently writing a server-client application that need to transfer some file to work. I'm using this method:

client:

file_to_send = raw_input(">") 

try:
    f = open("./sent_files/" + file_to_send, "rb")
except IOError, e:
    print ">error: ", e
    break

data = xmlrpclib.Binary(f.read())

if s.receive_file(file_to_send, data):
    print ">file correctly sent"

server:

def receive_file(self, name, arg):                                        
    with open("./sampletest/"+name, "wb") as handle: 
        handle.write(arg.data)

But how can I do the opposite (I mean sending a file from the server to the client) ?

1
  • It seems that the client and server are running on the same machine, and you just call server's function in client code. Commented May 28, 2013 at 12:35

1 Answer 1

7

Just write a function on the server like this:

def send_file(self, name):
  with open('./sampletest/' + name, 'rb') as handle:
    return handle.read()

and call this on the client:

data = send_file(fileName)
with open('./received_files/' + fileName, 'wb') as handle:
  handle.write(data)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.