Hello Community,
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:

ftp_delete()
ftp_nlist()
ftp_rmdir()

http://php.net/manual/en/ref.ftp.php

You can also use functions like opendir(), unlink() and rmdir():

unlink('ftp://user:password@ftp_server');

but in the case of rmdir and ftp_rmdir the directory needs to be always empty and you need permissions, so in some occasions you'll need to use chmod() or ftp_chmod() since the ftp user is different from the server user, usually www-data.

In Addition
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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.