Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Fileman fileop function

Discussion in 'cPanel Developers' started by Visad182, Jul 24, 2018.

Tags:
  1. Visad182

    Visad182 Member

    Joined:
    Sep 8, 2017
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    fdggfd
    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$chCURLOPT_HTTPAUTHCURLAUTH_BASIC );
    curl_setopt$chCURLOPT_USERPWD$username ':' $password );
    curl_setopt$chCURLOPT_SSL_VERIFYHOSTfalse );
    curl_setopt$chCURLOPT_SSL_VERIFYPEERfalse );

    // Set up a POST request with the payload.
    curl_setopt$chCURLOPT_POSTtrue );
    curl_setopt$chCURLOPT_POSTFIELDS$payload );
    curl_setopt$chCURLOPT_RETURNTRANSFERtrue );

    // 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


    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...
     
  2. Visad182

    Visad182 Member

    Joined:
    Sep 8, 2017
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    fdggfd
    cPanel Access Level:
    Website Owner
    May someone explain me this please ?

    I really don't know why we pay for license fee but have no support...
     
  3. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    44,367
    Likes Received:
    1,857
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello @Visad182,

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

    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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice