我目前正在编写一个服务器客户端应用程序,需要传输一些文件才能工作。
我正在使用这个方法:
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)
但我怎样才能做相反的事情(我的意思是从服务器发送文件到客户端)?
只需要写一个函数就可以了server像这样:
def send_file(self, name):
with open('./sampletest/' + name, 'rb') as handle:
return handle.read()
并称其为client:
data = send_file(fileName)
with open('./received_files/' + fileName, 'wb') as handle:
handle.write(data)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)