Reputation: 19
A friend of mine asked me to help cleaning her cPanel account because it got infected with malware. I logged in to cPanel and the built-in file manager crashed after a few minutes because this malware created 100.000s of folders and it couldn't even process it. Some of those are empty, the others are containing a few malicious PHP files. These folders names are just numbers (for example: 1979190). I tried to delete them through FTP but it's just not an option. My FTP client can only show 10.000 folders at a time. I tried to delete those but 2 hours later it's still deleting the folders with the first number sequence (1******) and the last folders are starting with number 9.
Unfortunately there's no SSH access for this account. I have contacted the support too but they won't help (they want us to pay $100 before they can run a single shell command...)
So my question is: What is the best way to delete all of those folders from the public_html directory? Is there a PHP script that could help? Maybe something that could delete all folders where the folder name is just numbers?
Any idea could help! Thank you in advance!
Upvotes: 1
Views: 1674
Reputation: 23848
Use this script. It goes through the nested directories and remove them all.
<?php
function rrmdir($dir) {
if (is_dir($dir)) {
$objects = scandir($dir);
foreach ($objects as $object) {
if ($object != "." && $object != "..") {
if (filetype($dir."/".$object) == "dir")
rrmdir($dir."/".$object);
else unlink ($dir."/".$object);
}
}
reset($objects);
rmdir($dir);
}
}
?>
Upvotes: 0