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:
$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