FTP - Remove files and folders at light speed
Stop the slow process of deleting files via FTP! Learn how to remove entire websites and folders at lightning speed using a simple, self-deleting PHP script—even without SSH access.
This article is over a year old but was reviewed on July 30, 2026 — the content is still accurate.
This article is part of the WinSCP & remote file transfer series:
- KeePass - Overriding the URL field
- WinSCP - Retrieve a stored password
- Fatal error was starting Putty after having saved settings
- WinSCP - Synchronize host and remote
- FTP - Remove files and folders at light speed
- WinSCP - Visual Basic for Application use
- WinSCP - Download files with specific extension recursively
- Search your FTP server at lightning speed

This article shares a small erase.php script you can upload via FTP and run once from the browser to instantly wipe an entire website folder server-side, avoiding the painfully slow file-by-file deletion through an FTP client — with a strong warning that it deletes everything immediately, with no confirmation or backup.
Have you ever deleted a website from your FTP client? It's easy, just select the folder containing the website and press the delete key.
Easy, simple and ... so slow. It takes ages to delete files and folders. Several dozen minutes! Ouch.
If you've an SSH connection to your web server and if you're comfortable with it; you can rm -rf the folder and it'll be done in seconds.
But what if you don't have SSH or fear to make errors?
There is an alternative, the erase.php script.
Open your FTP client, open your website folder (like /var/www/html/old_site); the one you wish to remove and create a new file called f.i. erase.php then copy/paste the code below in it.
<?php
$script_name = basename(__FILE__);$directory = dirname(__FILE__);
echo '<h1>Deleting all files and subfolders in '.$directory.'</h1>';
$it = new RecursiveDirectoryIterator($directory);
foreach (new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST) as $file) { if ( ($file->isDir()) && (!in_array($file->getFilename(), array('.', '..'))) ){ echo '<h3>Deleting folder '.$file->getPathname().'</h3>'; rmdir($file->getPathname()); } else { if ( ($file->isFile()) && ($file->getPathname()!=__FILE__) ) { echo '<p>Deleting file '.$file->getPathname().'</p>'; unlink ($file->getPathname()); } }}
echo '<h4 style="color:green;">Deletion complete. Only the '.$script_name.' file remains in the folder.</h4>';
unlink(__FILE__);?>This script recursively deletes all files and folders within its own directory, then deletes itself. It uses PHP's recursive directory iterator to walk through the directory tree from the bottom up, removes folders and files (except itself during the loop), displays progress messages, and finally removes the script file itself.
Start your browser, navigate to your website (http://your_old_site.com) and add /erase.php at the end to run the script.
Make sure this is what you want
Be really sure this is what you want
Be extremely sure this is what you want
The script will then start immediately and will remove everything without asking confirmation nor backup. Just killing files and folders.
At the end of the process (i.e. in just a few seconds), the folder will be completely empty.
And, exactly like the QuickScan scanner, remember to delete erase.php from your server as soon as you're done: a script able to wipe a folder has no business staying reachable from the Internet.
This article is part of the WinSCP & remote file transfer series:
- KeePass - Overriding the URL field
- WinSCP - Retrieve a stored password
- Fatal error was starting Putty after having saved settings
- WinSCP - Synchronize host and remote
- FTP - Remove files and folders at light speed
- WinSCP - Visual Basic for Application use
- WinSCP - Download files with specific extension recursively
- Search your FTP server at lightning speed





