1

请帮助我的任何人我求求你我一直在寻找一个月每天尝试不同的东西没有任何工作。

下面的脚本将创建 ftp 帐户,但它在“添加 ftp 帐户”这一行中定义为测试目录,如何将此脚本连接到 html 表单,以便该脚本可以通过该 html 表单创建一个 ftp 帐户。谢谢你

   <?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 ( $curl, CURLOPT_SSL_VERIFYPEER , 0 ) ;
  curl_setopt ( $curl, CURLOPT_RETURNTRANSFER , 1 ) ;
  curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST , 0 ) ;
  curl_setopt ( $curl, CURLOPT_USERPWD        , $conn [ 'user' ] . ':' . $conn [ 'pass' ] ) ;
  curl_setopt ( $curl, CURLOPT_HEADER         , 0 ) ;
  curl_setopt ( $curl, CURLOPT_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' ) ;
?>
4

1 回答 1

0

如何在 cpanel 中创建 ftp 帐户:

<?
$user = $cpenal_user; // the cpenal root username
$pass = $cpenal_pass; // the cpanel root password
$domain = $site_domain; // the cpanel root domain
$fquota = $drive_space; // ftp disc space mb (for new ftp account)
$skin = 'x3'; // cpnel version


$fuser =  //the username for the new  FTP account
$fpass =  //default password for new ftp account

$uri = '/directiry/'; // the internal URL to the FTP home folder /directiry/ 


if (mkdir($uri, 0777)) { //make the tmp directory
    $fDirectory = '/directiry/';

    //$fuser = $feedUser;

    $fhomedir = '/public_html/' . $fDirectory;


    $url = "https://$user:$pass@$domain:2083/frontend/$skin/ftp/doaddftp.html?";
    $url = $url . "login=$fuser&password=$fpass&homedir=$fhomedir&quota=$fquota";

    $result = @file_get_contents($url);
    if (preg_match('/(Account created successfully)/', $result)) {

       //ftp created with new directory
    }} ?>
于 2015-01-05T16:16:35.270 回答