第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 PHP 下載和存儲遠程密碼保護文件

使用 PHP 下載和存儲遠程密碼保護文件

PHP
拉風的咖菲貓 2021-11-26 15:48:12
當我在任何瀏覽器的地址欄中輸入: https://username:password@www.example.com/Protected/Export/MyFile.zip 時,文件會正常下載。現(xiàn)在我正在嘗試對 PHP 執(zhí)行相同的操作:連接到遠程受密碼保護的文件并將其下載到本地目錄(如 ./downloads/)。我已經(jīng)嘗試了多種 PHP 方法(ssh2_connect()、copy()、fopen()、...),但都沒有成功。$originalConnectionTimeout = ini_get('default_socket_timeout');ini_set('default_socket_timeout', 3); // reduces waiting time$connection = ssh2_connect("www.example.com");// use $connection to download the fileini_set('default_socket_timeout', $originalConnectionTimeout);if($connection !== false) ssh2_disconnect($connection);輸出:“警告:ssh2_connect():無法在端口 22 [..] 上連接到 www.example.com”如何使用 PHP 下載此文件并將其存儲在本地目錄中?
查看完整描述

2 回答

?
翻翻過去那場雪

TA貢獻2065條經(jīng)驗 獲得超14個贊

當訪問一個 url 時


https://username:password@www.example.com/Protected/Export/MyFile.zip

您正在使用HTTP Basic Auth,它發(fā)送AuthorizationHTTP 標頭。這與 無關ssh,因此您不能使用ssh2_connect().


要使用 php 訪問它,您可以使用 curl:


$user = 'username';

$password = 'password';

$url = 'https://www.example.com/Protected/Export/MyFile.zip';


$curl = curl_init();

// Define which url you want to access

curl_setopt($curl, CURLOPT_URL, $url);


// Add authorization header

curl_setopt($curl, CURLOPT_USERPWD, $user . ':' . $password);


// Allow curl to negotiate auth method (may be required, depending on server)

curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);


// Get response and possible errors

$response = curl_exec($curl);

$error = curl_error($curl);

curl_close($curl);


// Save file

$file = fopen('/path/to/file.zip', "w+");

fputs($file, $reponse);

fclose($file);


查看完整回答
反對 回復 2021-11-26
?
慕慕森

TA貢獻1856條經(jīng)驗 獲得超17個贊

這不是 SSH 協(xié)議。它可能類似于Apache HTTP 身份驗證。您可以遵循并嘗試本指南:使用 PHP 進行 HTTP 身份驗證


查看完整回答
反對 回復 2021-11-26
  • 2 回答
  • 0 關注
  • 221 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號