script for retrieving XML files?

MAXreefer

New member
I would like to retrieve the status.xml and datalog.xml from my apex and use the retrieved data for my personal website.
Does anybody know if there is a php script or so which would do the trick?

Thanks
Michael
 
I posted PHP code a while back... despite the "ac3" in the file name, it does work with Apex. There are two files... one outputs the status in HTML table format, the other as a PNG image. The code in the files is an early version of what's used today on Reeftronics
 
I posted PHP code a while back... despite the "ac3" in the file name, it does work with Apex. There are two files... one outputs the status in HTML table format, the other as a PNG image. The code in the files is an early version of what's used today on Reeftronics

Het Russ,
thanks for the script but I can't get it to work.
I replaced all the credentials, IP etc. and uploaded it to my server (runs php scripts).
I always get the message "Could not retrieve XML file" in my browser.
I see on the server the "status.xml" is created when I run your script but it is empty.
I know I can access the Apex from my browser using my external IP, port.

Any hints?
Thanks again
Michael
 
Michael, try using wget by itself. I used wget in the public code since its broadly supported, but your hosting provider may not permit it. I'm on my iphone awaiting a flight home at the moment, but I'll dig up the code for an alternate method of retrieving the XML when I get a chance. Or search RC for it. It's out there here in the Neptune forum somewhere.
 
I found the old post...

Delete or comment out the two lines for wget, and add the lines for a different method to try as listed:


<code style="white-space: nowrap;"> <code></code></code>
PHP:
//exec("wget -q -O status.xml - http://$username:$password@$hostname:$port/cgi-bin/status.xml",$xmlget,$err); 
//if ($err) die("Could not retrieve XML file") 
ini_set('allow_url_fopen', 'on'); 
$f_url = 'http://'.$username.':'.$password.'@'.$hostname.':'.$port.'/cgi-bin/status.xml'; 
file_put_contents('status.xml', file_get_contents($f_url)); 
ini_set('allow_url_fopen', 'off');
 
Thanks so much Russ for taking your time and effort to help me with this.
Really appreciate it.

I replaced the code you suggested but still not working.
Here is the response what I got into my browser. I used "XXXX" to grey out my IP and folder location:
----------------------------------------------------
Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /XXXXXXXXX/30/d239770530/htdocs/elos120/apex/ac3xml-table.php on line 26

Warning: file_get_contents(http://...@XXXXXXXXXX:XX/cgi-bin/status.xml) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in /XXXXXXXXXX/30/d239770530/htdocs/elos120/apex/ac3xml-table.php on line 26

Warning: fread() [function.fread]: Length parameter must be greater than 0 in /XXXXXXXXXXX/30/d239770530/htdocs/elos120/apex/ac3xml-table.php on line 81
Could not read XML file
---------------------------------------------------

Line 26 in the script: file_put_contents('status.xml', file_get_contents($f_url));
Line 81 in the script: $fp = fopen($xml_file, "r") or die("Could not open XML file");
 
"URL file-access is disabled in the server configuration"

Your host is not allowing the file_get_contents function to execute.
 
When using this code:
exec("wget -q -O status.xml - http://$username:$password@$hostname:$port/cgi-bin/status.xml",$xmlget,$err);
if ($err) die("Could not retrieve XML file");

I always get "Could not retrieve XML file".

This code:
ini_set('allow_url_fopen', 'on');
$f_url = 'http://'.$username.':'.$password.'@'.$hostname.':'.$port.'/cgi-bin/status.xml';
file_put_contents('status.xml', file_get_contents($f_url));
ini_set('allow_url_fopen', 'off');

result in "failed to open stream: Connection refused"

Any ideas?
Thanks,
 
Run wget from the command line in a telnet/SSH session using the verbose option:

Code:
wget -v http://username:password@hostname:port/cgi-bin/status.xml
Look for the error messages to help diagnose. Wget may not even be available to you.


The error you are getting with the other code is probably due to restrictions set on the hosting server. Some hosting providers firewall outbound connections. GoDaddy is a notable example. I have a hunch that this is what you are encountering. You may want to call tech support and ask if they do block ports outbound.

Also: neither of these examples will work if you use a complex password containing otherwise reserved characters like @, !, :, %, &, etc.
 
Thanks Russ! That was it! My host block outbound ports. Therefore when using an unconventional port for my Apex, I basically shot myself in the foot. After switching back to port 80 I can now use wget to access the XML file.
Thanks Again!
 
Back
Top