0

Having trouble deleting a directory/folder via ftp php script..

I am getting a weird warning in my php log, and the ftp_delete function is not working. Please see below

PHP LOG says:

PHP Warning: ftp_delete(): End in C:\Hosting\HYPV\website.com\wwwroot\Services\TestDelete.php on line 29

<?php


require('../FTPconfig.php');

$conn_id = ftp_connect($ftp_server);

$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

ftp_pasv($conn_id,true);

$contents = ftp_nlist($conn_id, "/FTP/website.com/wwwroot/Clients/clientName/Reports/");


if ($contents == true) {

foreach ($contents as $file) {

    $local_file = $file;
    $server_file = '/FTP/website.com/wwwroot/Clients/clientName/Reports/'.$file;

    ftp_delete($conn_id, $server_file); //<------------------- PHP LOG says: ftp_delete(): End in C:\Hosting\HYPV\website.com\wwwroot\Services\TestDelete.php on line 29

}

} else {

    echo "No files available.";

}


ftp_close($conn_id);


?>
  • What is the value of `$file` when the error happens? – Barmar Jan 18 '19 at 21:55
  • The same value as the path in which it supposed to delete. I am trying to delete all the directories within a folder. – Christhemist Jan 18 '19 at 21:57
  • 1
    You're deleting subdirectories? Unix won't allow you to delete a directory unless it's already empty. – Barmar Jan 18 '19 at 21:59
  • Also PHP's FTP implementation is buggy and if your FTP server returns more than one line of data in a command response [also buggy, but lots of servers do it] you can wind up with nonsensical warnings like this. – Sammitch Jan 18 '19 at 22:27
  • Ok I have written a function to empty the contents of the directory but now how do I delete the directory?? – Christhemist Jan 18 '19 at 22:38

1 Answers1

0

I figured it out thanks to Barmar. I needed to empty the contents of the directory first and then I needed to use the ftp_rmdir function to delete the directory. ftp_delete wasn't working...