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.

forms - Help to make a form to create ftp account

Discussion in 'cPanel Developers' started by dude179, Jun 24, 2013.

  1. dude179

    dude179 Registered

    Joined:
    Jun 22, 2013
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Reseller Owner
    Hi every one,

    I have this script to create a ftp account without cpanel but it only make the account without the form so as soon as it execute on browser it would create the account as specify in "ADD Ftp Account. How can I make the html form connect with this script so it work through the html form , I'm curious if it can have user email & details sent to me by email and to user email upon completion. I have tried many thing for over a month nothing is working. Please help me out I would appreciate that. Thank You

    PHP:
       <?php
    $conn 
    = array ( 'host' => 'Domain Name'
                  
    'port' => '2083'
                  
    'user' => 'Not Avi'
                  
    'pass' => 'Not Avi'
                  
    ) ;

    function 
    cpanel_api $conn $type $user $pass $domain )
    {
     if ( 
    $conn 'port' ] == '2087' || $conn 'port' ] == '2083' || $conn 'port' ] == '443' )
     {
        
    $site 'https://' $conn 'host' ] . ':' $conn 'port' ] ;
     } else {
        
    $site 'http://' $conn 'host' ] . ':' $conn 'port' ] ;
     }

     switch ( 
    $type )
     {
        case 
    'add_ftp' :
         
    $xmlin '<cpanelaction><module>Ftp</module><func>addftp</func><apiversion>1</apiversion><args>' $user '</args><args>' $pass '</args><args>/' $user '</args><args>20</args></cpanelaction>' ;
         break ;

        case 
    'del_ftp' :
         
    $xmlin '<cpanelaction><module>Ftp</module><func>delftp</func><apiversion>1</apiversion><args>' $user '</args><args>1</args></cpanelaction>' ;
         break ;

        case 
    'add_subdomain' :
         
    $xmlin '<cpanelaction><module>SubDomain</module><func>addsubdomain</func><apiversion>1</apiversion><args>' $user '</args><args>' $domain '</args><args>0</args><args>0</args><args>/' $user '</args></cpanelaction>' ;
         break ;

        case 
    'del_subdomain' :
         
    $xmlin '<cpanelaction><module>SubDomain</module><func>delsubdomain</func><apiversion>2</apiversion><args><domain>' $user $domain '</domain></args></cpanelaction>' ;
         break ;

        default :
         echo 
    'Type error' ;
     }

     if ( 
    $type == 'add_ftp' || $type == 'del_ftp' || $type == 'add_subdomain' || $type == 'del_subdomain' )
     {
      
    $query '/xml-api/cpanel?user=' $conn 'user' ] . '&xmlin=' $xmlin ;

      
    $curl curl_init ( ) ;
      
    curl_setopt $curlCURLOPT_SSL_VERIFYPEER ) ;
      
    curl_setopt $curlCURLOPT_RETURNTRANSFER ) ;
      
    curl_setopt $curlCURLOPT_SSL_VERIFYHOST ) ;
      
    curl_setopt $curlCURLOPT_USERPWD        $conn 'user' ] . ':' $conn 'pass' ] ) ;
      
    curl_setopt $curlCURLOPT_HEADER         ) ;
      
    curl_setopt $curlCURLOPT_URL            $site $query ) ;
      
    $result curl_exec $curl ) ;
      
    curl_close $curl ) ;
     }
    }

    /***** ADD Subdomain and FTP Account *****/
    cpanel_api $conn 'add_subdomain' 'test' '0123456789' '.domain.com' ) ;
    cpanel_api $conn 'add_ftp'       'test' '0123456789' '.domain.com' ) ;

    /***** DEL Subdomain and FTP Account *****/
    //cpanel_api ( $conn , 'del_subdomain' , 'test' , '0123456789' , '.domain.com' ) ;
    //cpanel_api ( $conn , 'del_ftp'       , 'test' , '0123456789' , '.domain.com' ) ;
    ?>
     
    #1 dude179, Jun 24, 2013
    Last edited: Jun 24, 2013
  2. PlotHost

    PlotHost Well-Known Member

    Joined:
    Apr 29, 2011
    Messages:
    253
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    US
    cPanel Access Level:
    Root Administrator
    Twitter:
    Take a look here /http://www.html.net/tutorials/php/lesson11.php
     
  3. dude179

    dude179 Registered

    Joined:
    Jun 22, 2013
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Reseller Owner
    Thank You for aLL YOUR HELP.

    i'm able to do so after all.

    But I have one problem that is it is creating ftp directories in main root not in public_html.

    So in this script how can I specify so it makes the directories as in specified folder.

    I read some articles so I know a little bit.

    I found the command is "homedir"(The FTP account's root directory. This should be relative to the account's public_html directory.) and "homedir2"(The path to the FTP account's root directory. This value should be relative to the account's home directory) . Also it has to specify in "add_ftp" . The only problem is how? I tried to use the same command as for user or quota it doesn't work. I'm curious if you know anything about it.


    I would really appreciate your in this matter.

    Thank You again.

    Happy Independence Day!
     
  4. dude179

    dude179 Registered

    Joined:
    Jun 22, 2013
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Reseller Owner
    Need Help to Specify Directory for Ftp Account Api Script

    Hi How are You?

    I need help to specify a directory in ftp account creator. I have script already working but it is making directory in main root no even in public_html. I want to specify some directory so it will create new directories for ftp in this specify directory.

    I found the command is "homedir"(The FTP account's root directory. This should be relative to the account's public_html directory.) and "homedir2"(The path to the FTP account's root directory. This value should be relative to the account's home directory) . Also it has to specify in "add_ftp" . The only problem is how? I tried to use the same command as for user or quota it doesn't work. I'm curious if you know anything about it.

    here is the script I'm using
    PHP:
       <?php
    $conn 
    = array ( 'host' => 'Domain Name'
                  
    'port' => '2083'
                  
    'user' => 'Not Avi'
                  
    'pass' => 'Not Avi'
                  
    ) ;

    function 
    cpanel_api $conn $type $user $pass $domain )
    {
     if ( 
    $conn 'port' ] == '2087' || $conn 'port' ] == '2083' || $conn 'port' ] == '443' )
     {
        
    $site 'https://' $conn 'host' ] . ':' $conn 'port' ] ;
     } else {
        
    $site 'http://' $conn 'host' ] . ':' $conn 'port' ] ;
     }

     switch ( 
    $type )
     {
        case 
    'add_ftp' :
         
    $xmlin '<cpanelaction><module>Ftp</module><func>addftp</func><apiversion>1</apiversion><args>' $user '</args><args>' $pass '</args><args>/' $user '</args><args>20</args></cpanelaction>' ;
         break ;

        case 
    'del_ftp' :
         
    $xmlin '<cpanelaction><module>Ftp</module><func>delftp</func><apiversion>1</apiversion><args>' $user '</args><args>1</args></cpanelaction>' ;
         break ;

        case 
    'add_subdomain' :
         
    $xmlin '<cpanelaction><module>SubDomain</module><func>addsubdomain</func><apiversion>1</apiversion><args>' $user '</args><args>' $domain '</args><args>0</args><args>0</args><args>/' $user '</args></cpanelaction>' ;
         break ;

        case 
    'del_subdomain' :
         
    $xmlin '<cpanelaction><module>SubDomain</module><func>delsubdomain</func><apiversion>2</apiversion><args><domain>' $user $domain '</domain></args></cpanelaction>' ;
         break ;

        default :
         echo 
    'Type error' ;
     }

     if ( 
    $type == 'add_ftp' || $type == 'del_ftp' || $type == 'add_subdomain' || $type == 'del_subdomain' )
     {
      
    $query '/xml-api/cpanel?user=' $conn 'user' ] . '&xmlin=' $xmlin ;

      
    $curl curl_init ( ) ;
      
    curl_setopt $curlCURLOPT_SSL_VERIFYPEER ) ;
      
    curl_setopt $curlCURLOPT_RETURNTRANSFER ) ;
      
    curl_setopt $curlCURLOPT_SSL_VERIFYHOST ) ;
      
    curl_setopt $curlCURLOPT_USERPWD        $conn 'user' ] . ':' $conn 'pass' ] ) ;
      
    curl_setopt $curlCURLOPT_HEADER         ) ;
      
    curl_setopt $curlCURLOPT_URL            $site $query ) ;
      
    $result curl_exec $curl ) ;
      
    curl_close $curl ) ;
     }
    }

    /***** ADD Subdomain and FTP Account *****/
    cpanel_api $conn 'add_subdomain' 'test' '0123456789' '.domain.com' ) ;
    cpanel_api $conn 'add_ftp'       'test' '0123456789' '.domain.com' ) ;

    /***** DEL Subdomain and FTP Account *****/
    //cpanel_api ( $conn , 'del_subdomain' , 'test' , '0123456789' , '.domain.com' ) ;
    //cpanel_api ( $conn , 'del_ftp'       , 'test' , '0123456789' , '.domain.com' ) ;
    ?>




    I would really appreciate your in this matter.


    Thank You

    Happy Independence Day!
     
  5. KostonConsulting

    KostonConsulting Well-Known Member

    Joined:
    Jun 17, 2010
    Messages:
    255
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    San Francisco, CA
    cPanel Access Level:
    Root Administrator
    Re: Need Help to Specify Directory for Ftp Account Api Script

    For API1 Ftp::addftp(), homedir is relative to $home/public_html. If you specify '/$user', it will create the directory at $home/public_html/$user. If you want $home/$user, you will need to specify '../$user'.

    I'd really recommend using API2 though as this is a newer API and the code is more up to date. (Ftp Module Documentation)

    For API2, you can also specify the argument names in the XML so the code is much easier to read.

    Note: in API2, homedir is relative to $home, not $home/public_html

    This should create a FTP account that has a root of $home/$user:

    Code:
    $xmlin = '<cpanelaction><module>Ftp</module><func>addftp</func><apiversion>2</apiversion><data><user>' . $user . '</user><pass>' . $pass . '</pass><quota>20</quota><homedir>' . $user . '</homedir></data></cpanelaction>' ; 
    
    WARNING: You really should use the cPanel XML-API PHP Class or update your class based on what you see in their class. You're not taking into account cPanel's security tokens so your script will break on newer versions of cPanel which have security tokens turned on by default.

    Here's their PHP API class:

    https://github.com/CpanelInc/xmlapi-php

    Here's an example of using API2:

    https://github.com/CpanelInc/xmlapi-php/blob/master/Examples/api2_example.php
     
  6. dude179

    dude179 Registered

    Joined:
    Jun 22, 2013
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Reseller Owner
    Re: Need Help to Specify Directory for Ftp Account Api Script

    Hi,

    thank you for reply.

    but however it doesnt work. as describe it wont create a account at all.
    I'm curious about xml api 2 , do I have to specify any thing in xmlapi file such as account information. and in the example where I do I specify the dir and more info that I will make to create ftp account. thanks
    I wonder whats wrong with it.
     
  7. KostonConsulting

    KostonConsulting Well-Known Member

    Joined:
    Jun 17, 2010
    Messages:
    255
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    San Francisco, CA
    cPanel Access Level:
    Root Administrator
    Re: Need Help to Specify Directory for Ftp Account Api Script

    Code:
    $xmlin = '<cpanelaction><module>Ftp</module><func>addftp</func><apiversion>2</apiversion><args><user>' . $user . '</user><pass>' . $pass . '</pass><quota>20</quota><homedir>' . $user . '</homedir></args></cpanelaction>' ;
    
    Sorry about that, looks like I used <data> rather than <args>. Fixed above.


    I'm not sure if I understand the above. The username of the cPanel account is specified in the &user= URL variable. The account information of the FTP user is in the children of the <args> tag above.

    These variables are in the <args> tag. Please read the documentation for their specific meaning: Ftp Module Documentation
     
Loading...

Share This Page