XML API Uploadfiles not working properly?
Hello everyone.
I'm working on a project right now to create automaticly account and send files after the account creation.
I'm working with XML API.
Right now, createaccs is working very well without any problem.
But i'm trying to make uploadfiles working but i've alway the same error which is
But i already specified the upload file. Here is my PHP code, and i had tryed everything, every form of path, with / or without... Still have the same error. [PHP]password_auth($cpanel_account,$cpanel_password); $xmlapi->set_port('2083'); $destination_dir = "home/myAccount/public_html/gros"; $newdir_name = "public_html/wp-links-opml.php"; $api2args = array( 'dir'=> 'public_html/gros', 'file-1' => '/home/immobill/accont/wp-links-opml.php' ); $xmlapi->set_output('json'); print $xmlapi->api2_query($cpanel_account, 'Fileman', 'uploadfiles', $api2args); ?>[/PHP] Can someone tell me what is the problem :\ ? Will be very appreciated. Thank
{"cpanelresult":{"event":{"result":1},"error":"You must specify at least one file to upload.","apiversion":2,"data":[{"uploads":[],"succeeded":0,"failed":0,"warned":0}],"module":"Fileman","func":"uploadfiles"}}But i already specified the upload file. Here is my PHP code, and i had tryed everything, every form of path, with / or without... Still have the same error. [PHP]password_auth($cpanel_account,$cpanel_password); $xmlapi->set_port('2083'); $destination_dir = "home/myAccount/public_html/gros"; $newdir_name = "public_html/wp-links-opml.php"; $api2args = array( 'dir'=> 'public_html/gros', 'file-1' => '/home/immobill/accont/wp-links-opml.php' ); $xmlapi->set_output('json'); print $xmlapi->api2_query($cpanel_account, 'Fileman', 'uploadfiles', $api2args); ?>[/PHP] Can someone tell me what is the problem :\ ? Will be very appreciated. Thank
-
Same thing for this part of your own code in your API doc. [PHP] $destination_dir, 'file-1' => $cf ); // Set up the cURL request object. $ch = curl_init( $request_uri ); curl_setopt( $ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC ); curl_setopt( $ch, CURLOPT_USERPWD, $username . ':' . $password ); curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, false ); curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ); // Set up a POST request with the payload. curl_setopt( $ch, CURLOPT_POST, true ); curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); // Make the call, and then terminate the cURL caller object. $curl_response = curl_exec( $ch ); curl_close( $ch ); // Decode and validate output. $response = json_decode( $curl_response ); if( empty( $response ) ) { echo "The cURL call did not return valid JSON:\n"; die( $response ); } elseif ( !$response->status ) { echo "The cURL call returned valid JSON, but reported errors:\n"; die( $response->errors[0] . "\n" ); } // Print and exit. die( print_r( $response ) ); ?>[/PHP] The cURL call did not return valid JSON:
This is the harder and much complicated API i ever worked with. Documentation is verry bad explained, all PHP code is not working, have to find it by another github user. This is crazy.0 -
Hello @Visad182, I recommend against using the XML-like output of our API in your custom script. See the following quote from our Tutorial - Use UAPI's Fileman::upload_files Function in Custom Code document: $destination_dir, 'file-1' => $cf ); // Set up the cURL request object. $ch = curl_init( $request_uri ); curl_setopt( $ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC ); curl_setopt( $ch, CURLOPT_USERPWD, $username . ':' . $password ); curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, false ); curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ); // Set up a POST request with the payload. curl_setopt( $ch, CURLOPT_POST, true ); curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); // Make the call, and then terminate the cURL caller object. $curl_response = curl_exec( $ch ); curl_close( $ch ); // Decode and validate output. $response = json_decode( $curl_response ); if( empty( $response ) ) { echo "The cURL call did not return valid JSON:\n"; die( $response ); } elseif ( !$response->status ) { echo "The cURL call returned valid JSON, but reported errors:\n"; die( $response->errors[0] . "\n" ); } // Print and exit. die( print_r( $response ) ); ?>
Additionally, can you clarify how you will be uploading the files in this project? For instance, is it the same files every time, or are you manually uploading custom files during each account creation in your project? Thank you.0 -
Hello Michael, thank for your help. Finaly, files was uploaded. I think problem was files paths... Here is the working code: [PHP] $destination_dir, 'file-1' => $cf ); // Set up the cURL request object. $ch = curl_init( $request_uri ); curl_setopt( $ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC ); curl_setopt( $ch, CURLOPT_USERPWD, $username . ':' . $password ); curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, false ); curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ); // Set up a POST request with the payload. curl_setopt( $ch, CURLOPT_POST, true ); curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); // Make the call, and then terminate the cURL caller object. $curl_response = curl_exec( $ch ); curl_close( $ch ); // Decode and validate output. $response = json_decode( $curl_response ); if( empty( $response ) ) { echo "The cURL call did not return valid JSON:\n"; die( $response ); } elseif ( !$response->status ) { echo "The cURL call returned valid JSON, but reported errors:\n"; die( $response->errors[0] . "\n" ); } // Print and exit. die( print_r( $response ) ); ?>[/PHP] Just a little question @cPanelMichael about this path /home/trycp/try.zip Does this zip in this path (trycp is the username of cpanel user), so can you confirm me this ZIP files right at this path can't be accessible from other person except the respective Cpanel user ? I just want this ZIP to not be accessible to anybody except via the API, with cpanel username and everything... so, this is a protected path right ? thank 0 -
Just a little question @cPanelMichael about this path /home/trycp/try.zip Does this zip in this path (trycp is the username of cpanel user), so can you confirm me this ZIP files right at this path can't be accessible from other person except the respective Cpanel user ? I just want this ZIP to not be accessible to anybody except via the API, with cpanel username and everything... so, this is a protected path right ?
Hello, That path is not accessible to the public because it's outside of the default document root of your website. Accessing that path requires authentication with the cPanel username and password. Thank you.0
Please sign in to leave a comment.
Comments
4 comments