Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    2

    Default How to Copy file between account with xml-api, api2?

    Hi,

    I just want to copy a file "test.zip" from one account to another in the same server with the xml-api class call for example:
    $account="root";
    $sourcefiles="/home/acct1/public_html/test.zip";
    $destinationfiles="/home/acct2/public_html/test.zip";
    $op = "copy";
    $res = $xmlapi->api2_query($account, "Fileman", "fileop", array( $op, $sourcefiles,$destinationfiles) );

    But is not working. I'm authenticating with root user

    What is the best way to achieve this task?

    I just want to copy the file to the other account and then unzip the file there in acct2.



    Thanks for your help!

  2. #2
    Integration Developer cPanelDavidN's Avatar
    Join Date
    Dec 2009
    Location
    Houston, TX
    Posts
    525

    Default Re: How to Copy file between account with xml-api, api2?

    Hi gennerp,

    There's two issues with the example code you propose:
    1) API2 functions take named parameters, ie 'destfiles'='/some/file'. This behavior/requirement is expressed in PHP with an associative array. ex:
    PHP Code:
    $args = array(
        
    'sourcefiles'      => '/home/acct1/public_html/test.zip'
        
    'destfiles' => '/home/acct2/public_html/test.zip'
        
    'op' => 'copy',
    );
    $r $xmlapi->api2_query($account"Fileman""fileop"$args ); 
    --- the key names for this particular function are documented here:ApiFileman < ApiDocs/Api2 < TWiki -- Their in bold, under the Parameters section

    2) API1 and API2 functions are perform on as the cPanel user. In the case of the XML-API where the authenticated user is 'root' or a reseller, the action is perform on their behalf.
    ...essentially, the request goes into the listening daemon, cpsrvd, and privilege is descalated to the cPanel user account, and then the request is performed...sort of like a su - $cp_user.

    An XML-API request examines the HTTP POST/GET data for 'cpanel_xmlapi_user' (or cpanel_jsonapi_user) to determine which cPanel user to work as. In the PHP XML-API client class this key/value pair is generated base on the first argument to api1_query()/api2_query(). In your case, is the value of the $account variable. However, you have provide 'root' as the value for $account, which will not work since 'root' is not a valid cPanel account.

    Fileman functions are intended to be used by and for a single account and will depend on the cPanel config data of a specific cPanel user. Furthermore, this functions (mostly) assume that the cPanel user can only operate within their home directory (and subdirectories) and will not allow file operations outside of that area.

    I have three suggests, though I'm sure there's some others that I can't think of at the moment:
    1) use ftp:

    a) log in as acct1 (if you don't know acct1's password, you can use the root password [provided you have not disabled the password override feature in WHM Tweak Settings])
    b) ftp 'get' the file, placing it on the local machine
    c) exit ftp as acct1 and log back in as acct2
    d) ftp 'put' the file into desired destination
    -- There's built in FTP functions, PHP: FTP - Manual
    2) use ssh:

    a) login as root and issue the necessary commands.
    -- You can use a pure PHP class(library of classes), like phpseclib. Or you can try installing and using the SSH2 PECL package. Generally speaking, I've personally had better success with the phpseclib on any given project, since is doesn't require any addition extensions or libs
    3) make a folder belonging to a "share" group

    a) make a unix group 'acctshare'
    b) create /path/share/dir in a sane, out of the way place
    c) make sure the directory is owned by the 'acctshare' group, possibly setting it to read-only
    d) add each user you which to have access to the 'acctshare' group
    e) drop you files in the directory, and set ownership/permissions accordingly
    f) as the user (either via ftp, ssh or possible a Fileman operation) copy the target file into various destination.
    Regards,
    -DavidN
    David Neimeyer
    Integration Developer

    sdk.cpanel.net
    APIs: XML-API API1 & API2
    Check Out: Developer Downloads Integration Blog
    Need Support? Support Ticket Developer Forum Feature Request

Similar Threads & Tags
Similar threads

  1. restoring an account with xml-api
    By AL-Kateb in forum cPanel Developers
    Replies: 6
    Last Post: 07-30-2010, 02:37 PM
  2. Security Question, xml-api, api2
    By willsmelser in forum cPanel Developers
    Replies: 3
    Last Post: 12-24-2009, 11:58 PM
  3. Uploading HTML File to a Domain by XML/cPanel API
    By mizanurl in forum New User Questions
    Replies: 0
    Last Post: 11-16-2009, 12:52 PM
  4. XML-API issues with API1 and API2 commands
    By XenomediaBV in forum cPanel Developers
    Replies: 7
    Last Post: 09-14-2009, 11:34 AM
  5. Can we list the b/w used by an account with XML-API ?
    By Indianets in forum cPanel Developers
    Replies: 4
    Last Post: 02-07-2009, 02:23 PM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube