Question

I have been using this script to create FTP accounts very successfully

// your cPanel username
$cpanel_user = 'usernam';

// your cPanel password
$cpanel_pass = 'password';

// your cPanel skin
$cpanel_skin = 'x3';

// your cPanel domain
$cpanel_host = 'domain.com';

// ftp username
$ftp_user = 'user';

 // ftp password
$ftp_pass = 'ftp_password';

// ftp home directory
$ftp_home = 'home';

// ftp quota
$ftp_quota = '0';

// create the ftp account
$request = "http://{$cpanel_user}:{$cpanel_pass}@{$cpanel_host}:2082";
$request .= "/frontend/{$cpanel_skin}/ftp/doaddftp.html";
$request .= "?login={$ftp_user}";
$request .= "&password={$ftp_pass}";
$request .= "&homedir=public_html/{$ftp_user}";
//$request .= "a={$ftp_quota}";
$result = file_get_contents($request);
echo $result;
?> 

But this assumes that I have the domain pointed to the hosting. I am wanting to have this script work with a domain that is not pointed to a domain yet.

Example: http://123.456.78.910~user/

Does that make sense?

Was it helpful?

Solution

If you open up that IP address and the cPanel port, you can login with any user account. So just set the IP address in $cpanel_host instead of the domain, for now. It'll create it, since you can access cPanel through (following your example IP) http://123.456.78.910:2082, and you could login just as though it were through the domain itself.

OTHER TIPS

Tried and Tested...

You need to enter variables

$cpaneluser = Your cpanel username
$cpanelpass = Your cpanel password
$domain = your domain name ( xyz.com )
$fuser = ftp username
$fpass = ftp password
$homedir = ftp directory 

$url = "http://$cpaneluser:$cpanelpass@$domain:2082/json-api/cpanel?";
$url .= "cpanel_jsonapi_version=2&cpanel_jsonapi_module=Ftp&cpanel_jsonapi_func=addftp&";
$url .= "user=$fuser&pass=$fpass&homedir=$fhomedir&quota=0";

var_dump($url);
$result = @file_get_contents($url);
if ($result === FALSE) 
die("ERROR: FTP Account not created. Please make sure you passed correct parameters.");
echo $result;

hope it helps..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top