Mistake in API1[Fileman::restorefiles] function usage - pls help.

Alwar

Member
Mar 7, 2011
5
0
51
Hi,

I am writting script to automate the restore process from remote host. To automate restore process, i found one API1[Fileman::restorefiles] function to restore a partial backup.
so that i used that function and made the following URL to call this trough XML API calls.

http://<HOST_NAME>:2082/xml-api/cpanel?user=alwar&cpanel_xmlapi_module=Fileman&cpanel_xmlapi_func=restorefiles&cpanel_xmlapi_apiversion=1

post values :
=================
"arg-0=/home/alwar& arg-1=file-E:/file-backup-3.23.2011_17-01-36_alwar.tar.gz"

And I requested this URL through using CURL in remote windows machine.

I used the following sampele scripts to request this API function.

Code:
CURLResponse _cURLResponse;
string _url = "http://<HOST_NAME>:2082/xml-api/cpanel?user=alwar&cpanel_xmlapi_module=Fileman&cpanel_xmlapi_func=restorefiles&cpanel_xmlapi_apiversion=1";
strinng _postField = "arg-0=/home/alwar& arg-1=file-E:/file-backup-3.23.2011_17-01-36_alwar.tar.gz";
curl_easy_setopt(curlPtr, CURLOPT_URL, _url.c_str());	/* set the URL */
curl_easy_setopt(curlPtr, CURLOPT_VERBOSE, 0);
curl_easy_setopt(curlPtr, CURLOPT_POSTFIELDS, _postField.c_str()); /* set POST field */
curl_easy_setopt(curlPtr, CURLOPT_WRITEFUNCTION, CPanelAPI::ResponseWriter); /* set CALL_BACK function */
curl_easy_setopt(curlPtr, CURLOPT_WRITEDATA, &_cURLResponse); /* set FOURTH ARG for CALL_BACK function */
curl_easy_perform(curlPtr);	/* process given URL */
curl_easy_getinfo(curlPtr, CURLINFO_RESPONSE_CODE, &errNo);
if(errNo == 200 || errNo == 204)
	std::cout << _cURLResponse.GetOutputData() << "\n";
else
	std::cout << "Error occured when URL was requested "<< errNo  << "\n";
After i ran this script, i did not get expected result that is mentioned in cPanel API document.

Instead, I got the following result.

Code:
<?xml version="1.0" ?>
<cpanelresult>
 <module>Fileman</module>
 <func>restorefiles</func>
 <type>event</type>
 <source>internal</source>
 <apiversion>1</apiversion>
 <data>
  <result></result>
 </data>
 <event>
  <result>1</result>
 </event>
</cpanelresult>
could you any one tell me that what mistake i have done in my script ? or Whether this script can not be called through XML API ?

Regards,
Alwar
 
Last edited:

MattDees

Well-Known Member
Apr 29, 2005
416
1
243
Houston, TX
cPanel Access Level
Root Administrator
Looking at this shortly, you should either remove your argv-0 parameter or change it to "restorefile"

if that does not work, PLEASE let me know and I'll begin working on finding a better solution for you.
 

Alwar

Member
Mar 7, 2011
5
0
51
Hi matt,

Thanks for your reply, I tried this as you said and made POST value like following
"arg-1=file-E:/file-backup-3.23.2011_17-01-36_alwar.tar.gz" [Removed arg-0]

and also tried with following POST value
"restorefile=/home/alwar&arg-1=file-E:/file-backup-3.23.2011_17-01-36_alwar.tar.gz"[Renamed arg-0 to restorefile]

Unfortunately, I got same result[empty resultset XML] by using both POST values.

Thanks,
Alwar
 

MattDees

Well-Known Member
Apr 29, 2005
416
1
243
Houston, TX
cPanel Access Level
Root Administrator
Using the restorefiles command, there isn't any need for the arg-0 or arg-1 parameters. This call only takes FORM fields.

Also, are you doing this via WHM or cpanel?
 

Alwar

Member
Mar 7, 2011
5
0
51
Hi matt,

Thanks for your help. I have resolved this issue by calling "restorefiles" command with FORM fields.

regards,
Alwar