登录到FTP服务器
@return boolean true-登录成功，false-登录失败
541227
private function login(){
        extract($this->config);
        $this->link = ftp_connect($host, $port, $timeout);
        if($this->link) {
            if (ftp_login($this->link, $username, $password)) {
               return true;
            } else {
                $this->error = "无法登录到FTP服务器：username - {$username}";
            }
        } else {
            $this->error = "无法连接到FTP服务器：{$host}";
        }
        return false;
    }
1142350
public function loadProviderFiles()
    {
        //debug $this->logMessage('ProviderCommunication::loadProviderFile: START','botdetection_debug');
        $lastWeek = time() - (7 * 24 * 60 * 60);

        if (false === $this->allowUrlOpen) 
        {
            $this->logMessage('ProviderCommunication::loadProviderFiles allowUrlOpen = false!', 'botdetection_debug');

            return false;
        }

        foreach($this->referrerProvider as $source => $url) 
        {
            if (false === file_exists($this->cachePath .'/'. strtolower($source) . '.txt') || 
                 $lastWeek > filemtime($this->cachePath .'/'. strtolower($source) . '.txt') 
               )
            {
                //debug $this->logMessage('ProviderCommunication::loadProviderFile: '.$source,'botdetection_debug');
                $fileProvider = fopen($this->cachePath .'/'. strtolower($source) . '.txt', 'wb+');
                fwrite($fileProvider, file_get_contents($url));
                fclose($fileProvider);
            }
        }
        //debug $this->logMessage('ProviderCommunication::loadProviderFile: END','botdetection_debug');
        return true;
    }
879153
protected function getFtpConnection()
    {
        if (is_null($this->ftpConnection)) {
            $host = $this->connection['host'];
            $user = $this->connection['user'];
            $pass = $this->connection['pass'];

            $this->ftpConnection = $this->connect($host, $user, $pass);

            // set timeout
            ftp_set_option($this->ftpConnection, FTP_TIMEOUT_SEC, $this->connection['timeout']);

            // set passive mode if it's defined
            if (null !== $pasv = $this->getPasv()) {
                ftp_pasv($this->ftpConnection, $pasv);
            }
        }

        return $this->ftpConnection;
    }
441112
public static function ip()
    {
        if (!self::isDebug()) {
            return false;
        }

        $ip = self::getClientIP();

        $data = array(
            'ip'        => $ip,
            'host'      => gethostbyaddr($ip),
            'source'    => '$_SERVER["' . self::getClientIP(true) . '"]',
            'inet_pton' => inet_pton($ip),
            'ip2long'   => ip2long($ip),
        );

        return self::i()->dump($data, '! my IP = ' . $ip . ' !');
    }
791398
public function connect()
    {
        if ($this->connection) {
            return true;
        }

        $config = $this->config + $this->defaultConfig;

        $dsn = sprintf(
            '%s:host=%s;port=%p;dbname=%s',
            self::DSN_PREFIX,
            $config['host'],
            $config['port'],
            $config['database']
        );

        if ($config['unix_socket']) {
            $dsn = sprintf(
                '%s:unix_socket=%s;dbname=%s',
                self::DSN_PREFIX,
                $config['unix_socket'],
                $config['database']
            );
        }

        $this->connection = new PDO(
            $dsn,
            $config['username'],
            $config['password'],
            $config['options']
        );

        return true;
    }
1251400
public function initLoad(): bool
    {
        $tasks = $this->getTasks();

        if (\count($tasks) <= 0) {
            return false;
        }

        foreach ($tasks as $tasksIndex => $task) {
            $this->checkTaskCount();
            $time = time();
            $key = $this->getKey($task['cron'], $task['task'], $task['method']);
            // 防止重复写入任务
            if (! $this->getOriginTable()->exist($key)) {
                $this->getOriginTable()->set($key, [
                    'rule'       => $task['cron'],
                    'taskClass'  => $task['task'],
                    'taskMethod' => $task['method'],
                    'add_time'   => $time
                ]);
            }
        }

        return true;
    }
1023515
public function syst()
	{
		// If native FTP support is enabled lets use it...
		if (FTP_NATIVE)
		{
			if (($ret = @ftp_systype($this->conn)) === false)
			{
				Log::add(__METHOD__ . 'Bad response.', Log::WARNING, 'jerror');

				return false;
			}
		}
		else
		{
			// Send print working directory command and verify success
			if (!$this->_putCmd('SYST', 215))
			{
				Log::add(sprintf('%1$s: Bad response.  Server response: %2$s [Expected: 215]', __METHOD__, $this->response), Log::WARNING, 'jerror');

				return false;
			}

			$ret = $this->response;
		}

		// Match the system string to an OS
		if (strpos(strtoupper($ret), 'MAC') !== false)
		{
			$ret = 'MAC';
		}
		elseif (strpos(strtoupper($ret), 'WIN') !== false)
		{
			$ret = 'WIN';
		}
		else
		{
			$ret = 'UNIX';
		}

		// Return the os type
		return $ret;
	}
159590
public function ftpFiles($dir)
    {
        return ($this->isConnected() === true) ? ftp_nlist($this->getConnection(), $dir) : false;
    }
511802
public function upFile()
    {
        $file = UploadedFile::getInstanceByName($this->fileField);
        $validator = new FileValidator($this->config);
        if ($validator->validate($file, $error)) {
            //设置文件名称
            $this->oriName = $file->name;
            //设置文件大小
            $this->fileSize = $file->size;
            $this->fileType = $this->getExtension();
            $this->fullName = $this->getFullName();
            $this->filePath = $this->getFilePath();
            $this->fileName = $this->getFileName();
            $dirName = dirname($this->filePath);
            if (!is_dir($dirName)) {//递归创建保存目录
                FileHelper::createDirectory($dirName, $this->dirMode, true);
            }
            if (!($file->saveAs($this->filePath) && file_exists($this->filePath))) {
                $this->stateInfo = Yii::t('attachment', 'An error occurred while saving the file.');
                return false;
            } else { //移动成功
                $this->saveModel();
                $this->stateInfo = 'SUCCESS';
                return true;
            }
        }
        return false;
    }
237758
private function remoteLogin()
    {
        $ftp_login = true;
        $connet = ftp_connect($this->host, $this->port);
        $login = ftp_login($connet, $this->user, $this->pwd);
        if (!$connet || $login) {
            $this->tips = 'connet';
            $ftp_login = false;
        }
        $this->link = $connet;
        ftp_pasv($this->link, true);
        return $ftp_login;
    }
604021
public function delete($file)
    {
        return ($this->isConnected() === true) ? ftp_delete($this->getConnection(), $file) : false;
    }
1216358
public function save()
    {
        if (!empty($this->log)) {

            if (!$this->check($this->config)) {
                // 检测日志写入权限
                return false;
            }

            if (empty($this->config['level'])) {
                // 获取全部日志
                $log = $this->log;
                if (!$this->config['debug'] && isset($log['debug'])) {
                    unset($log['debug']);
                }
            } else {
                // 记录允许级别
                $log = [];
                foreach ($this->config['level'] as $level) {
                    if (isset($this->log[$level])) {
                        $log[$level] = $this->log[$level];
                    }
                }
            }

            $result = $this->driver->save($log);
            if ($result) {
                $this->log = [];
            }

            return $result;
        }

        return true;
    }
429753
public function systype() {
		$this->connectIfNeeded();
		$res = @ftp_systype($this->handle);
		return $res == null || $res == false ? 'UNIX' : $res;
	}
861337
private function doStatic() {
        $conf = $this->config;

        if(!$conf['enable']) {
            return false;
        }

        $ext = Request::driver()->ext;
        if(!$ext || false === strpos($conf['allow'], $ext)) {
            return false;
        }

        $request  = Request::driver();
        $response = Response::driver();

        $path = $conf['path'] . $request->pathinfo;
        if (!is_file($path)) {
            $response->status(404);
            return true;
        }
        $expire = $conf['expire'];
        if ($expire) {
            $fstat = stat($path);
            //过期控制信息
            if (isset($request->header['if-modified-since'])) {
                $lastModifiedSince = strtotime($request->header['if-modified-since']);
                if ($lastModifiedSince and $fstat['mtime'] <= $lastModifiedSince) {
                    //不需要读文件了
                    $response->status(304);
                    return true;
                }
            }
        }
        $response->header('Cache-Control',"max-age={$expire}");
        $response->header('Pragma',"max-age={$expire}");
        $response->header('Last-Modified',date('D, d-M-Y H:i:s T', $fstat['mtime']));
        $response->header('Expires',"max-age={$expire}");
        $response->header('Content-Type',Response::$mimes[$ext]);
        echo file_get_contents($path);
        return true;

    }
973923
public function clearFile()
    {
        $cleared = false;

        if (isset($this->file_pointer)) {
            $cleared = $this->file_pointer->ftruncate(0);
        }

        return $cleared;
    }
39118
public function uploadFile()
    {
        if (!$this->request->files->has('file')) {
            return false;
        }
        $file   = $this->request->files->get('file');
        $upload = rtrim($this->uploadDir, '/');
        if (!is_dir($upload)) {
            mkdir($upload, 0777, true);
        }
        $file->move(realpath($upload), $file->getClientOriginalName());

        return sprintf('/%s/%s', pathinfo($upload, PATHINFO_BASENAME),
            pathinfo($file->getClientOriginalName(), PATHINFO_BASENAME));
    }
603226
public function disconnect()
    {
        if (false === $this->connected) {
            return true;
        }

        if ($this->socket) {
            $this->send(WebsocketPayload::generateClosePayload(), WebsocketPayload::OPCODE_CLOSE);
            $this->closing = true;

            $payloadLength = ord(fread($this->socket, 1));
            $payload = fread($this->socket, $payloadLength);

            if ($this->closing) {
                $this->closing = false;
            } else {
                if ($payloadLength >= 2) {
                    $bin = $payload[0] . $payload[1];
                    $status = bindec(sprintf('%08b%08b', ord($payload[0]), ord($payload[1])));

                    $this->send($bin . 'Close acknowledged: ' . $status, WebsocketPayload::OPCODE_CLOSE);
                }
            }

            fclose($this->socket);
            $this->connected = false;

            return true;
        }

        return false;
    }