journal_stage_obj->where("journal_stage_id", $stage_id)->find(); $list = $this->article_obj->where("journal_stage_id", $stage_id)->select(); $journal_info = $this->journal_obj->where("journal_id", $stage_info['journal_id'])->find(); $count = 0; foreach ($list as $v) { $local_file = XmlBuilder::forArticle($v['article_id']); $file = substr($v['doi'], strpos($v['doi'], "/") + 1) . ".xml"; $remote_file = "/" . $journal_info['title'] . "/" . $stage_info['stage_year'] . "v" . $stage_info['stage_vol'] . "n" . $stage_info['stage_no'] . "-" . $file; $this->pushFtp($remote_file, $local_file); $localPdf = ROOT_PATH . "public/articlePDF/" . $v['file_pdf']; $remotePdf = "/" . $journal_info['title'] . "/" . $stage_info['stage_year'] . "v" . $stage_info['stage_vol'] . "n" . $stage_info['stage_no'] . "-" . substr($v['doi'], strpos($v['doi'], "/") + 1) . ".pdf"; $this->pushFtp($remotePdf, $localPdf); $count++; } return PushResult::success("EBSCO 已上传 {$count} 篇文章的 XML/PDF"); } private function pushFtp($remote_file, $local_file) { $cred = $this->cred('ebsco'); $con = ftp_connect($cred['host'], $cred['port']); if (!$con) { throw new \Exception('EBSCO FTP 连接失败'); } $res = ftp_login($con, $cred['user'], $cred['pass']); if (!$res) { ftp_close($con); throw new \Exception('EBSCO FTP 登录失败'); } ftp_pasv($con, true); $data = ftp_put($con, $remote_file, $local_file, FTP_BINARY); ftp_close($con); if (!$data) { throw new \Exception('EBSCO FTP 上传失败: ' . $remote_file); } } }