Removing a directory using XML-API
In the previous article, we have shown you how to connect to cPanel’s front end (2082/2083) ports. In this article we will show you how to delete a directory in your file system using XML-API in PHP.
Let’s say you want to delete a directory named ‘deleteme‘ in public_html directory. So the path is /home/USER/public_html/deleteme. However, we don’t need to bother with /home/USER part. We just need to provide the path started from public_html.
For deleting, we will use api2 query’s Fileman module! Here is how you should execute it:
$directory = ‘public_html/deleteme’;
$result = $cpanel->api2_query(‘cPanel Username’, ‘Fileman’, ‘fileop’, array(‘op’=>’unlink’,'sourcefiles’=>$directory));
That’s it!
If you are not still clear how to use XML-API Service, here is more details.
require_once(‘xmlapi.php’);
$cpanel = new xmlapi();
$cpanel->set_host(‘CP_DOMAIN’);
$cpanel->set_port(2083);
$cpanel->password_auth(‘CP_USERNAME’, ‘CP_PASSWORD’);$directory = ‘public_html/deleteme’;
$result = $cpanel->api2_query(‘CP_USERNAME’, ‘Fileman’, ‘fileop’, array(‘op’=>’unlink’,'sourcefiles’=>$directory));
a WordPress rating system
Related posts:
- Effective Solutions for 500 error (Premature End of Script Headers)
- cPanel JailShell, Unmount and Clean Virtfs
- How to connect cPanel’s ports using XML-API (PHP Class)?
- Delete some specific files from all subdirectories
- Creating FTP accounts in Enkompass control panel!