2
Contributors
1
Reply
5
Views
4 Years
Discussion Span
Last Post by cereal
1

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.

Edited by cereal

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.