4

i have the following simple script to list the ftp accounts but i am unable to get it to work as i have the following error as soon as it tries to call the constructor

 include '/usr/local/cpanel/php/cpanel.php';
$cpanel = new CPANEL(); // Connect to cPanel - only do this once.

// List FTP account information.
$list_ftp_accts = $cpanel->uapi('Ftp', 'list_ftp');
echo "<pre>";
print_r($list_ftp_accts);

Fatal error: Uncaught exception 'RuntimeException' with message 'There was a problem fetching the env variable containing the path to the socket' in /usr/local/cpanel/php/cpanel.php:146 Stack trace: #0 /public_html/uapi.php(4): CPANEL->__construct() #1 {main} thrown in /usr/local/cpanel/php/cpanel.php on line 146

Line 146 in cpanel.php

$socketfile = getenv('CPANEL_PHPCONNECT_SOCKET');
Muhammad Omer Aslam
  • 22,976
  • 9
  • 42
  • 68

2 Answers2

5

According to a post on the cPanel forums, you can only use LiveAPI from within cPanel's document root, meaning your code would need to be in either /usr/local/cpanel/base/frontend/ or /usr/local/cpanel/base/3rdparty/. I ran into this while trying to use it in a WHM plugin (which would reside in /usr/local/cpanel/whostmgr/docroot/), and apparently that causes the same problem. If you're trying to run this from within cPanel or WHM, this page has some debugging steps you can try walking through.

If you're trying to run this code on a different server or from within a normal website's hosting account, you'll definitely need to use a different interface, such as the XML or JSON API. These are unfortunately somewhat confusingly documented, but the Guide to WHM API 1 page should get you started.

Dan Hlavenka
  • 3,697
  • 8
  • 42
  • 60
-1

Me too got the same error.

Try changing your file extension to your_file.live.php, instead of your_file.php. It solved the issue for me.

Referred the documentation here.

Chris.ZA
  • 1,218
  • 1
  • 15
  • 30