Back to FtpClient class

Method chmod

public bool
chmod
(mixed $path, mixed $mode)
Method to change mode for a path on the FTP server
Parameters
  • string $path Path to change mode on
  • mixed $mode Octal value to change mode to, e.g. '0777', 0777 or 511 (string or integer)
Returns
  • bool True if successful
Since
  • 1.5
Class: FtpClient
Project: Joomla

Method chmod - Source code

/**
 * Method to change mode for a path on the FTP server
 *
 * @param   string  $path  Path to change mode on
 * @param   mixed   $mode  Octal value to change mode to, e.g. '0777', 0777 or 511 (string or integer)
 *
 * @return  boolean  True if successful
 *
 * @since   1.5
 */
public function chmod($path, $mode)
{
    // If no filename is given, we assume the current directory is the target
    if ($path == '') {
        $path = '.';
    }
    // Convert the mode to a string
    if (\is_int($mode)) {
        $mode = decoct($mode);
    }
    // If native FTP support is enabled let's use it...
    if (FTP_NATIVE) {
        if (@ftp_site($this->_conn, 'CHMOD ' . $mode . ' ' . $path) === false) {
            if (!IS_WIN) {
                Log::add(Text::sprintf('JLIB_CLIENT_ERROR_FTP_BAD_RESPONSE', __METHOD__), Log::WARNING, 'jerror');
            }
            return false;
        }
        return true;
    }
    // Send change mode command and verify success [must convert mode from octal]
    if (!$this->_putCmd('SITE CHMOD ' . $mode . ' ' . $path, array(200, 250))) {
        if (!IS_WIN) {
            Log::add(Text::sprintf('JLIB_CLIENT_ERROR_FTP_CHMOD_BAD_RESPONSE', __METHOD__, $this->_response, $path, $mode), Log::WARNING, 'jerror');
        }
        return false;
    }
    return true;
}