I was wondering if there is a way to delete a folder and everything in the folder in ftp.
You should get the file list inside the directory to delete, loop ftp_delete() for each and ftp_rmdir() for each subdirectory, but they need to be empty as the main directory to delete. So it's a bit tricky, the functions you need to use are:
You can also use functions like opendir(), unlink() and rmdir():
but in the case of
ftp_rmdir the directory needs to be always empty and you need permissions, so in some occasions you'll need to use
ftp_chmod() since the ftp user is different from the server user, usually www-data.
If you have to do a lot of this activity it could be better to place a script in the remote server, use cron to make it wait instructions and from local send a simple file or
$_POST with the name of the directory to delete, you can use ftp_* or even curl. Just make sure that these ftp accounts are jailed otherwise it becomes dangerous.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.