/**
* Get the size of the remote file.
*
* @param string $remote FTP path to file whose size to get
*
* @return mixed number of bytes or false on error
*
* @since 3.6.0
*/
public function size($remote)
{
if (FTP_NATIVE) {
$size = ftp_size($this->_conn, $remote);
// In case ftp_size fails, try the SIZE command directly.
if ($size === -1) {
$response = ftp_raw($this->_conn, 'SIZE ' . $remote);
$responseCode = substr($response[0], 0, 3);
$responseMessage = substr($response[0], 4);
if ($responseCode != '213') {
throw new \RuntimeException(Text::sprintf('JLIB_CLIENT_ERROR_FTP_BAD_RESPONSE', __METHOD__), 35);
}
$size = (int) $responseMessage;
}
return $size;
}
// Start passive mode
if (!$this->_passive()) {
throw new \RuntimeException(Text::sprintf('JLIB_CLIENT_ERROR_FTP_PASSIVE', __METHOD__), 36);
}
// Send size command to the FTP server
if (!$this->_putCmd('SIZE ' . $remote, array(213))) {
@fclose($this->_dataconn);
throw new \RuntimeException(Text::sprintf('JLIB_CLIENT_ERROR_FTP_NOT_EXPECTED_RESPONSE_PATH_SENT', __METHOD__, $this->_response, 213, $remote), 35);
}
return (int) substr($this->_responseMsg, 4);
}