The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

xmlapi and fileop

Discussion in 'cPanel Developers' started by lexand, Apr 13, 2010.

  1. lexand

    lexand Member

    Joined:
    Mar 18, 2010
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Ukraine
    Hi there

    Can anyone help me?

    I am trying to extract archive by using xmlapi.

    PHP:
    $this->api2_query($this->user'Fileman''fileop', array(
                
    'extract',
                
    '/home/domain/public_html/latest.zip',
                
    '/home/domain/public_html',
                
    0,
                
    ''
            
    ));
    But nothing happens.

    I've tried various combinations of the source and destination, but I always get same result.

    I used urlencode() for paths and set doubledecode to 1. I ommited /home/domain and have used only /public_html/...

    All paths and files are exist.

    So
    1. Should I use urlencode() and doubledecode for the paths?
    2. Maybe I am wrong in the order of the params. What order is correct?
    3. What paths I should use absolute or relative?

    thanks

    P.S.
    I have same problem with "listfiles" and "getfileactions". "listfiles" always return files from the home directory, even if I specified another. "getfileactions" return nothing.
     
  2. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    API2 call need literal keys; fileman operates in a chroot

    Hi lexand,

    Two things:
    1) API2 calls need to have there array keys literal, and therefore order doesn't matter. (API1 keys need to be ordered)
    Code:
    $api2args = array( 
                'op'=> 'extract', 
                'sourcefiles' =>'public_html/ld.zip', 
                'destfiles' =>'/public_html', 
                'doubledecode' => 0, 
                'metadata' => '', 
            );
    
    2) I think your path is incorrect. Fileman operates in a chroot environment. Well, I'm not certain that it's literally a chroot, but the fact is that your 'sourcefiles' are relative to your $user 's home directory. That said, I think that the operation ("op") will be performed relative to the "sourcefiles" path. You can see in my example above, in order for it to be placed in my $user 's docroot, I had to give the 'absolute' path of '/public_html' for my "destfiles". If I didn't it would have extracted my 'ld.zip' to something like '/home/dave/public_html/public_html/latest_unzipped'

    If you're using the our xmlapi client class, you can either set_debug(1) or wrap you api calls in a var_dump() and see the output. It should include error messages on failure.

    Code:
    $ip = '192.168.1.1';
    $account = 'dave';
    
    $xmlapi = new xmlapi($ip);
    $xmlapi->password_auth('root','secretpasswd');
    
    $api2args = array( 
                'op'=> 'extract', 
                'sourcefiles' =>'public_html/ld.zip', 
                'destfiles' =>'/public_html', 
                'doubledecode' => 0, 
                'metadata' => '', 
            );
    
    var_dump( $xmlapi->version() );
    var_dump($xmlapi->api2_query($account, 'Fileman', 'fileop', $api2args));
    
    outputs:
    Code:
    object(SimpleXMLElement)#2 (1) {
      ["version"]=>
      string(7) "11.25.0"
    }
    object(SimpleXMLElement)#2 (5) {
      ["apiversion"]=>
      string(1) "2"
      ["data"]=>
      object(SimpleXMLElement)#4 (4) {
        ["dest"]=>
        string(22) "/home/dave/public_html"
        ["output"]=>
        string(65) "Archive:  /home/dave/public_html/ld.zip
       creating: latest_unzipped/
    "
        ["result"]=>
        string(1) "1"
        ["src"]=>
        string(29) "/home/dave/public_html/ld.zip"
      }
      ["event"]=>
      object(SimpleXMLElement)#3 (1) {
        ["result"]=>
        string(1) "1"
      }
      ["func"]=>
      string(6) "fileop"
      ["module"]=>
      string(7) "Fileman"
    }
    
    Hope that helps. Try those other functions and let me know I you still have any issues.

    Regards,
    -Dave
     
  3. lexand

    lexand Member

    Joined:
    Mar 18, 2010
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Ukraine
    Dave thank you very much.

    All function (I mean all functions that I've checked) work fine.
     
Loading...

Share This Page