Visad182

Member
Sep 8, 2017
10
0
1
Canada
cPanel Access Level
Website Owner
Hello,

i uploaded a ZIP, and i need to extract it.


Here is my code.

PHP:
<?php
// Log everything during development.
// If you run this on the CLI, set 'display_errors = On' in php.ini.
error_reporting(E_ALL);

// Declare your username and password for authentication.
$username = 'xxx';
$password = 'xxx';

// Define the API call.
$cpanel_host = 'localhost';
$request_uri = "https://$cpanel_host:2083/execute/Fileman/fileop";

$payload = array(
    'op'    => 'extract',
    'sourcesfiles' => 'public_html/damn/app.zip',
   'doubledecode' => '0'
);

// 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 ) );
?>

But i receive this error

The cURL call returned valid JSON, but reported errors: The system could not find the function “fileop” in the module “Fileman”.

This is a function, fileop right... ?

cPanel API 2 Functions - Fileman::fileop - Developer Documentation - cPanel Documentation

Otherwise, how can i extract file with PHP, i tried with other alternative from API1, without success...
 

cPanelMichael

Technical Support Community Manager
Staff member
Apr 11, 2011
47,911
2,233
363
cPanel Access Level
DataCenter Provider
Twitter
Hello @Visad182,

It looks like you are attempting to use a session-based API call for a cPanel API 2 function:

// Define the API call.
$cpanel_host = 'localhost';
$request_uri = "https://$cpanel_host:2083/execute/Fileman/fileop";
That type of call isn't supported with cPanel API 2 the way that it is with cPanel UAPI. You can scroll to the bottom of the following document and click on the various API types to see the supported methods of calling functions:

Guide to cPanel API 2 - Developer Documentation - cPanel Documentation

Also, note that a good approach when troubleshooting an issue with an API function is to test it out via the command line first. Here's an example of how to use this cPanel API 2 function via the command line:

Code:
# cpapi2 --user=username123 Fileman fileop op=extract sourcefiles=/home/username123/example.zip destfiles=/home/username123/ doubledecode=1
---
cpanelresult:
  apiversion: 2
  data:
    -
      dest: /home/username123
      output: "Archive:  /home/username123/example.zip\n extracting: 123                     \n extracting: 456                     \n"
      result: 1
      src: /home/username123/example.zip
  event:
    result: 1
  func: fileop
  module: Fileman
This command correctly extracted the files from /home/username123/example.zip to the /home/username123/ directory.

Keep in mind that opening a support ticket is a better approach if you require more immediate assistance (24/7 support is not offered on the cPanel Forums):

Create Support Ticket - Version 72 Documentation - cPanel Documentation

Thank you.