Back to FtpClient class

Method rename

public bool
rename
(mixed $from, mixed $to)
Method to rename a file/folder on the FTP server
Parameters
  • string $from Path to change file/folder from
  • string $to Path to change file/folder to
Returns
  • bool True if successful
Since
  • 1.5
Class: FtpClient
Project: Joomla

Method rename - Source code

/**
 * Method to rename a file/folder on the FTP server
 *
 * @param   string  $from  Path to change file/folder from
 * @param   string  $to    Path to change file/folder to
 *
 * @return  boolean  True if successful
 *
 * @since   1.5
 */
public function rename($from, $to)
{
    // If native FTP support is enabled let's use it...
    if (FTP_NATIVE) {
        if (@ftp_rename($this->_conn, $from, $to) === false) {
            Log::add(Text::sprintf('JLIB_CLIENT_ERROR_FTP_BAD_RESPONSE', __METHOD__), Log::WARNING, 'jerror');
            return false;
        }
        return true;
    }
    // Send rename from command to the server
    if (!$this->_putCmd('RNFR ' . $from, 350)) {
        Log::add(Text::sprintf('JLIB_CLIENT_ERROR_FTP_RENAME_BAD_RESPONSE_FROM', __METHOD__, $this->_response, $from), Log::WARNING, 'jerror');
        return false;
    }
    // Send rename to command to the server
    if (!$this->_putCmd('RNTO ' . $to, 250)) {
        Log::add(Text::sprintf('JLIB_CLIENT_ERROR_FTP_RENAME_BAD_RESPONSE_TO', __METHOD__, $this->_response, $to), Log::WARNING, 'jerror');
        return false;
    }
    return true;
}