Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    2

    Default Need help with remote access to cPanel API for creating secondary FTP accounts

    Hello,

    I've spent hours searching through the cPanel API docs, forums, etc. trying to find a solution to what I think is a fairly simple problem. I'm new to cPanel and fairly new to Php although I have a fair amount of programming experience.

    I am trying to figure out how to access cPanel remotely from a Php script so I can add secondary FTP accounts to my web hosting account.

    The client management software I am running on my domain provides a module that runs in the background written in Php that I can modify to perform remote tasks and then return status. (Note that this module executes in the background after a new customer successfully signs up - so there is no browser involved for input or output from/to the customer).

    It would really help if somebody could show me an example of how this could be done with the XMLAPI. Since that seems easiest (but any method that works is fine).

    Any help is appreciated!
    Dan

  2. #2
    Integration Developer cPanelDavidN's Avatar
    Join Date
    Dec 2009
    Location
    Houston, TX
    Posts
    525

    Default Re: Need help with remote access to cPanel API for creating secondary FTP accounts

    Hi Dan,

    You should take a look at our XML-API PHP client class. Its a PHP class that lets you make remote calls to a cPanel system. It's really ease to code with. Pretty much all you have to do is know your credential and the details of the API call you want. There are a few examples in the tarball; below is an example of how to call API2 Ftp::addftp (used to add FTP accounts)

    PHP Code:
    include("xmlapi.php");

    $ip "10.1.1.1";  //your server IP or name

    $xmlapi = new xmlapi($ip);  // instantiate the XML-API object

    //// If you need root or WHM/reseller level access, set root credentials and use port 2087/2086 
    //$auth_user = "root";
    //$auth_pass = "rootS3creT!";
    //$xmlapi->set_port(2087);

    //// If you're just authentiating against you cPanel, set cPanel credentials and use port 2083/2082
    /// for this example, I'll be "dave"
    $auth_user "dave";
    $auth_pass "daveS3creT!";
    $xmlapi->set_port(2083);

    //store our auth in object
    $xmlapi->password_auth($auth_user$auth_pass);

    //// Optional stuff
    // JSON or XML output
    $xmlapi->set_output('xml');
    // Debugging, great for at the console
    $xmlapi->set_debug(1);

    //// From API2 documents, this is want input is required by 'addftp' function
    /// Ftp::addftp( user, pass, homedir, quota, disallowdot, homedir2 )

    $args = array( 
      
    'user'=>'ftpuserx@davedomain.tld',
      
    'pass'=>'frc!%2Z2ltD',
      
    'quota'=>20
    );

    // for any cPanel API1 or API2 query you'll need to say what cPanel account you are affecting
    $cpuser 'dave';

    $response $xmlapi->api2_query($cpuser'Ftp''addftp'$args); 
    Checkout the links in my signature and search the forums for PHP XMLAPI and I'm sure you'll find tons of useful info

    Let me know if you have further questions,
    -DavidN
    David Neimeyer
    Integration Developer

    sdk.cpanel.net
    APIs: XML-API API1 & API2
    Check Out: Developer Downloads Integration Blog
    Need Support? Support Ticket Developer Forum Feature Request

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    2

    Default Re: Need help with remote access to cPanel API for creating secondary FTP accounts

    David,

    Thanks so much for your help on this - what you posted was exactly what I needed and it enabled me to get this thing working!

    It turned out however that I was not able to use the API2_query function as mentioned in your example and had to use API1_query instead because my cPanel version (11.26.20) did not support the API2 addftp function. (Only supported in 11.27 and after).

    That meant I had to figure out that API1 in my cPanel also supports an addftp function and that in order to access it I needed to call API1_query instead of API2_query. From there it was a matter of understanding the difference in how the argument array is processed in API1_qurey versus API2_qurey.

    All in all a very instructive problem for me. Thanks again to you for your help and guidance.
    Dan

  4. #4
    Integration Developer cPanelDavidN's Avatar
    Join Date
    Dec 2009
    Location
    Houston, TX
    Posts
    525

    Default Re: Need help with remote access to cPanel API for creating secondary FTP accounts

    Glad I could help. You bring up a great point about the availability of API2 addftp only in 11.27+.

    But it sounds like your well on your way! and yes API1 takes ordered parameters (and ordinal array) as opposed to API2 which takes named parameters (an associative array). The order for API1 Ftp::addftp should be:
    PHP Code:
    $args = array( $user$pass$homedir$quota$disallowdot$homedir2 ); 
    Best Regards,
    -DavidN
    David Neimeyer
    Integration Developer

    sdk.cpanel.net
    APIs: XML-API API1 & API2
    Check Out: Developer Downloads Integration Blog
    Need Support? Support Ticket Developer Forum Feature Request

Similar Threads & Tags
Similar threads

  1. XML/JSON API Function to retreive the 'Remote Access Key'
    By shaun in forum Feature Requests for cPanel/WHM
    Replies: 4
    Last Post: 02-08-2010, 02:36 PM
  2. curl, cPanel API and server remote access key question
    By sharmaine001 in forum Security
    Replies: 1
    Last Post: 01-25-2010, 01:49 PM
  3. cpanel api to create ftp accounts
    By spottedhaggis in forum cPanel Developers
    Replies: 1
    Last Post: 01-14-2010, 06:16 PM
  4. Creating User Accounts through API
    By qasim in forum cPanel and WHM Discussions
    Replies: 2
    Last Post: 05-04-2009, 10:44 AM
  5. Is there ANY way to access a secondary FTP acount from IE on Windows ???
    By mpierre in forum cPanel and WHM Discussions
    Replies: 12
    Last Post: 09-17-2003, 03:34 PM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube