MultiDev
MultiDev

Reputation: 10649

Deleting cPanel FTP account via PHP

I have a script that creates a cpanel FTP account like so:

$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);

I am trying to find out what the URL would be to delete the FTP account. I see the "doaddftp.html" and GET parameters. I assume there is a similar way to remove an FTP account.

Anyone know what the URL would be?

Upvotes: 1

Views: 617

Answers (2)

frobinsonj
frobinsonj

Reputation: 1167

This would work:

$buildRequest = '/execute/Ftp/delete_ftp?user='.$username.'&destroy=0'; # To remove the home directory of the ftp acc change to 1

$openSocket = fsockopen('localhost',2082);
if(!$openSocket) {
    return "Socket error";
    exit();
}

$authString = $cPanelUser . ":" . $cPanelPass;
$authPass = base64_encode($authString);
$buildHeaders  = "GET " . $buildRequest ."\r\n";
$buildHeaders .= "HTTP/1.0\r\n";
$buildHeaders .= "Host:localhost\r\n";
$buildHeaders .= "Authorization: Basic " . $authPass . "\r\n";
$buildHeaders .= "\r\n";

fputs($openSocket, $buildHeaders);
while(!feof($openSocket)) {
    fgets($openSocket,128);
}
fclose($openSocket);

Upvotes: 0

Manigandan Arjunan
Manigandan Arjunan

Reputation: 2265

The following link will be useful for you

http://docs.cpanel.net/twiki/bin/view/ApiDocs/Api2/ApiFtp#Ftp::delftp

Note:Delete an FTP account. This function is only available in cPanel 11.27.x and later.

Upvotes: 1

Related Questions