[phpxmlrpc] XMLRPC Binary Transfer

Gaetano Giunta giunta.gaetano at gmail.com
Thu Jan 22 10:34:23 CET 2009


Frank H a écrit :
> Hi all,
>
> I am trying to create a function that allows me to send binary files 
> from a client and have the server write it into a directory.
> I have it working right now, but it errors when I try to send a file 
> greater then about 300 Kb.  Any file under that size will
> transfer just fine.
>
> Here is the function I have on the server...
>
> function upload_file2($m)
> {
>     $param1 = $m->getParam(0);
>     $write_file = $param1->scalarval();
>     $convert_file = fopen($write_file, "rb");
>
>     $param2 = $m->getParam(1);
>     $file_name = $param2->scalarval();
>
>     $test_write = fopen("/tmp/".$file_name, "w");
>     fwrite($test_write, $write_file);
>     fclose($test_write);
>
>     return new xmlrpcresp(new xmlrpcval($file_name));
> }
>
> $upload_file2_sig = array(array($xmlrpcBase64,$xmlrpcBase64, 
> $xmlrpcString));
> $upload_file2_doc = 'uploads a binary file';
Apart from the fact that:
- I cannot understand the intended meaning of the line $convert_file = 
fopen($write_file, "rb");
- I hope you trust the source of webservice calls, as you're not 
validating $file_name for the presence of .. (or other similar escape) 
sequences
- you could test the result of fopen before doing fwrite+fclose
- the function signature should read 
array(array($xmlrpcString,$xmlrpcBase64, $xmlrpcString));
- you could probably return the numbers of bytes written instead of the 
filename
it looks fine.
>
> I am using a Python client to send the file.  I was playing around 
> with a Python server to transfer files and the Python
> server does not run into any problems with file size.
>
> This is what I have on the python client...
>
> import xmlrpclib
>
> print("Trying to connect...")
> server_url = 'http://some_url/new_server.php';
> server = xmlrpclib.Server(server_url);
>
> handle = open("nova.bmp")
> file_name = "fetch_nova.bmp"
> send_file = server.sendFile(xmlrpclib.Binary(handle.read()), file_name)
>
>
> This is the error I get when trying to use the Python Client/Php 
> Server combo
>
> Trying to connect...
> Traceback (most recent call last):
>   File "testProc_client.py", line 20, in ?
>     send_file = server.sendFile(xmlrpclib.Binary(handle.read()), 
> file_name)
>   File "/usr/lib/python2.3/xmlrpclib.py", line 1029, in __call__
>     return self.__send(self.__name, args)
>   File "/usr/lib/python2.3/xmlrpclib.py", line 1316, in __request
>     verbose=self.__verbose
>   File "/usr/lib/python2.3/xmlrpclib.py", line 1070, in request
>     headers
> xmlrpclib.ProtocolError: <ProtocolError for 
> mmodev.jpl.nasa.gov/frank/xmlrpc/demo/server/new_server.php: -1 >
Sorry, but the Python error does not help that much.

You should:
- check the php error log on the server for any hint
- check memory_limit, max_execution_time and especially post_max_size 
php.ini directives
- enable debug mode on the php server object

bye
Gaetano



More information about the phpxmlrpc mailing list