The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

API2 - addftp

Discussion in 'cPanel Developers' started by solcre, Apr 19, 2011.

  1. solcre

    solcre Registered

    Joined:
    Apr 19, 2011
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    When i try to use addftp it always return:

    array(
    ['apiversion'] =>
    2
    ...
    ['data'] =>
    array(
    ... 2 elements ... )

    ['reason'] =>
    'An account with that login already exists.'
    ...
    ['result'] =>
    0
    ...
    )
    ['error'] =>
    'An account with that login already exists.'
    ...
    ['event'] =>
    array(
    ... 1 element ... )

    ['result'] =>
    1
    ...
    )
    ['func'] =>
    'addftp'
    ...
    ['module'] =>
    'Ftp'
    ...
    )



    This is the $params i'm passing it:

    array(
    ['user'] =>
    'templates@mydomain.com'
    ...
    ['pass'] =>
    'ssadasdas'
    ...
    ['quota'] =>
    333
    ...
    ['homedir'] =>
    'templates'
    ...
    )


    Calling it like this: $retorno = $this->api2_query($user, "Ftp", "addftp", $params);

    Is there a bug on this?


    cPanel Version 11.28.87
     
  2. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Hi solcre,

    I have confirmed that API2 Ftp::addftp is working correctly. In the future, a more detailed inquiry would help determine how exactly you're trying to accomplish the task at hand.

    That is:
    1) I have to assume that you're using the PHP XML-API client class...but you don't say this explicitly
    - if so, what version of the PHP XML-API client class are you using?
    2) Is you script authentication as 'root' or the cPanel account?
    3) What port are you using?

    Re:
    1) There has been a update to the PHP XML-API client class in v1.0.6, itemized in the changelog, that ensures the function parameters, for calls like Ftp::addftp, don't munge the XML-API parameters.
    2 & 3) An incorrect pairing of port number and authenticated user can cause unexpected errors messages...sometimes similar to the one you've posted here...though this may not be you issue

    The following code, using the PHP XML-API v1.0.6, worked for me:
    PHP:
    include("xmlapi.php");

    $ip "10.1.1.1";
    $auth_user "dave";
    $auth_pass "secret!";
    $cpuser 'dave';


    $xmlapi = new xmlapi($ip);
    $xmlapi->password_auth$auth_user$auth_pass );

    $xmlapi->set_port('2083');
    $xmlapi->set_debug(1);

    $args = array( 
        
    'user'=>'templates',
        
    'pass'=>'d%29U2ltD',
        
    'quota'=>20,
        
    'homedir'=>'public_html/templates'
    );

    $xmlapi->api2_query($cpuser'Ftp''addftp'$args);
    The result was the following:
    Code:
    URL: https://10.1.4.1:2083/xml-api/cpanel
    DATA: user=templates&pass=d%2529U2ltD&quota=20&homedir=public_html%2Ftemplates&cpanel_xmlapi_user=dave&cpanel_xmlapi_module=Ftp&cpanel_xmlapi_func=addftp&cpanel_xmlapi_apiversion=2
    Authentication Header: Authorization: Basic ZGF2ZTpjcD--snip--
    
    
    RESPONSE:
     <?xml version="1.0" ?>
      <cpanelresult>
        <apiversion>2</apiversion>
        <data>
          <reason>OK</reason>
          <result>1</result>
        </data>
        <event>
          <result>1</result>
        </event>
        <func>addftp</func>
        <module>Ftp</module>
        <postevent>
          <result>1</result>
        </postevent>
        <preevent>
          <result>1</result>
        </preevent>
      </cpanelresult>
    
    SimpleXML var_dump:
    SimpleXMLElement Object
    (
        [apiversion] => 2
        [data] => SimpleXMLElement Object
            (
                [reason] => OK
                [result] => 1
            )
    
        [event] => SimpleXMLElement Object
            (
                [result] => 1
            )
    
        [func] => addftp
        [module] => Ftp
        [postevent] => SimpleXMLElement Object
            (
                [result] => 1
            )
    
        [preevent] => SimpleXMLElement Object
            (
                [result] => 1
            )
    
    )
    Regards,
    -DavidN
     
    #2 cPanelDavidN, Apr 20, 2011
    Last edited: Apr 20, 2011
Loading...

Share This Page