templateLibraryApiService = $templateLibraryApiService; } const HOST = '121.199.40.85'; const USER = 'root'; const PASSWORD = 'JGJHD84@8&a'; /** * Execute the console command. * * @return mixed */ public function handle() { /*try { $ssh2 = ssh2_connect(self::HOST, 22); ssh2_auth_password($ssh2, self::USER, self::PASSWORD); $siteId = 974; $domain = Site::query()->where('id', $siteId)->value('domain'); //远程目录 $targetDirectory = '/www/wwwroot/' . $domain . '/sepSsr/uploads'; //递归创建目录 $sftp = ssh2_sftp($ssh2); ssh2_sftp_mkdir($sftp, $targetDirectory, 0755, true); $connection = DB::connection($this->templateLibraryApiService->connection($siteId)); $imagesList = $connection->table('image')->get(); foreach ($imagesList as $item) { $imagePathArray = explode('storage', $item->src); $fileName = explode('/', $imagePathArray[1]); $file = array_pop($fileName); //本地目录 $sourceDirectory = base_path() . '/storage/app/public' . $imagePathArray[1]; $stream = ssh2_scp_send($ssh2, $sourceDirectory, $targetDirectory . '/' . $file, 0644); if ($stream) { $connection->table('image')->where('id', $item->id)->update(['is_synchronize' => 1]); } } } catch (\Exception $exception) { Log::info(date('Y-m-d H:i:s') . 'sync_pictures error!' . $exception->getMessage()); } Log::info(date('Y-m-d H:i:s') . 'sync_pictures success!');*/ } }