Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

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

Discussion in 'cPanel Developers' started by Alwar, Mar 28, 2011.

  1. Alwar

    Alwar Member

    Joined:
    Mar 7, 2011
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    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
     
    #1 Alwar, Mar 28, 2011
    Last edited: Mar 28, 2011
  2. MattDees

    MattDees Well-Known Member

    Joined:
    Apr 29, 2005
    Messages:
    416
    Likes Received:
    1
    Trophy Points:
    243
    Location:
    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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. Alwar

    Alwar Member

    Joined:
    Mar 7, 2011
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    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
     
  4. MattDees

    MattDees Well-Known Member

    Joined:
    Apr 29, 2005
    Messages:
    416
    Likes Received:
    1
    Trophy Points:
    243
    Location:
    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?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. Alwar

    Alwar Member

    Joined:
    Mar 7, 2011
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    51
    Hi matt,

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

    regards,
    Alwar
     
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice