/** * (non-PHPdoc) * @see \mithra62\Validate\RuleInterface::validate() * @ignore */ public function validate($field, $input, array $params = array()) { try { if ($input == '' || empty($params['0'])) { return false; } $params = $params['0']; if (empty($params['ftp_hostname']) || empty($params['ftp_password']) || empty($params['ftp_username']) || empty($params['ftp_port']) || empty($params['ftp_store_location'])) { return false; } $local = new Remote(new Local(dirname($this->getTestFilePath()))); $filesystem = new Remote(FTP::getRemoteClient($params)); if ($local->has($this->test_file)) { $contents = $local->read($this->test_file); $filesystem->getAdapter()->setRoot($params['ftp_store_location']); if ($filesystem->has($this->test_file)) { $filesystem->delete($this->test_file); } else { if ($filesystem->write($this->test_file, $contents)) { $filesystem->delete($this->test_file); } } } $filesystem->getAdapter()->disconnect(); return true; } catch (\Exception $e) { return false; } }
/** * (non-PHPdoc) * @see \mithra62\Validate\RuleInterface::validate() * @ignore */ public function validate($field, $input, array $params = array()) { try { if ($input == '' || empty($params['0'])) { return false; } $params = $params['0']; if (empty($params['ftp_hostname']) || empty($params['ftp_password']) || empty($params['ftp_username']) || empty($params['ftp_port'])) { return false; } $filesystem = new Remote(FTP::getRemoteClient($params)); if (!$filesystem->getAdapter()->listContents()) { return false; } $filesystem->getAdapter()->disconnect(); return true; } catch (\Exception $e) { return false; } }