Back to FtpClient class

Method delete

public bool
delete
(mixed $path)
Method to delete a path [file/folder] on the FTP server
Parameters
  • string $path Path to delete
Returns
  • bool True if successful
Since
  • 1.5
Class: FtpClient
Project: Joomla

Method delete - Source code

/**
 * Method to delete a path [file/folder] on the FTP server
 *
 * @param   string  $path  Path to delete
 *
 * @return  boolean  True if successful
 *
 * @since   1.5
 */
public function delete($path)
{
    // If native FTP support is enabled let's use it...
    if (FTP_NATIVE) {
        if (@ftp_delete($this->_conn, $path) === false) {
            if (@ftp_rmdir($this->_conn, $path) === false) {
                Log::add(Text::sprintf('JLIB_CLIENT_ERROR_FTP_BAD_RESPONSE', __METHOD__), Log::WARNING, 'jerror');
                return false;
            }
        }
        return true;
    }
    // Send delete file command and if that doesn't work, try to remove a directory
    if (!$this->_putCmd('DELE ' . $path, 250)) {
        if (!$this->_putCmd('RMD ' . $path, 250)) {
            Log::add(Text::sprintf('JLIB_CLIENT_ERROR_FTP_NOT_EXPECTED_RESPONSE_PATH_SENT', __METHOD__, $this->_response, 250, $path), Log::WARNING, 'jerror');
            return false;
        }
    }
    return true;
}