/**
* Verify the response code from the server and log response if flag is set
*
* @param mixed $expected Integer response code or array of integer response codes
*
* @return boolean True if response code from the server is expected
*
* @since 1.5
*/
protected function _verifyResponse($expected)
{
$parts = null;
// Wait for a response from the server, but timeout after the set time limit
$endTime = time() + $this->_timeout;
$this->_response = '';
do {
$this->_response .= fgets($this->_conn, 4096);
} while (!preg_match('/^([0-9]{3})(-(.*' . CRLF . ')+\\1)? [^' . CRLF . ']+' . CRLF . "\$/", $this->_response, $parts) && time() < $endTime);
// Catch a timeout or bad response
if (!isset($parts[1])) {
Log::add(Text::sprintf('JLIB_CLIENT_ERROR_FTP_TIMEOUT', __METHOD__, $this->_response), Log::WARNING, 'jerror');
return false;
}
// Separate the code from the message
$this->_responseCode = $parts[1];
$this->_responseMsg = $parts[0];
// Did the server respond with the code we wanted?
if (\is_array($expected)) {
if (\in_array($this->_responseCode, $expected)) {
$retval = true;
} else {
$retval = false;
}
} else {
if ($this->_responseCode == $expected) {
$retval = true;
} else {
$retval = false;
}
}
return $retval;
}