Created
November 2, 2016 19:20
-
-
Save meunomemauricio/2c7f9c1e9eed1b4f62de2b7ddf184fb6 to your computer and use it in GitHub Desktop.
How to transfer files through XMLRPC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python | |
"""Example XMLRPC Client which will receive the file.""" | |
import xmlrpclib | |
import zlib | |
class CheckSumError(RuntimeError): | |
"""CheckSum does not match.""" | |
def main(): | |
"""Main Routine.""" | |
proxy = xmlrpclib.ServerProxy('http://localhost:8000/') | |
xmlrpc_binary, file_crc = proxy.retrieve_file() | |
if file_crc == zlib.crc32(xmlrpc_binary.data): | |
with open('fetched_dummy_file.bin', 'wb') as handle: | |
handle.write(xmlrpc_binary.data) | |
else: | |
raise CheckSumError('CheckSum does not Match.') | |
if __name__ == '__main__': | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python | |
"""Example XMLRPC Server which will send the file.""" | |
import xmlrpclib | |
import zlib | |
from SimpleXMLRPCServer import SimpleXMLRPCServer | |
def retrieve_file(): | |
"""Send a Dummy file.""" | |
with open('dummy_file.bin', 'rb') as handle: | |
binary_file = handle.read() | |
xmlrpc_binary = xmlrpclib.Binary(binary_file) | |
file_crc = zlib.crc32(binary_file) | |
return xmlrpc_binary, file_crc | |
server = SimpleXMLRPCServer(('localhost', 8000)) | |
print 'Listening on port 8000...' | |
server.register_function(retrieve_file, 'retrieve_file') | |
server.serve_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment