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);

TA貢獻1856條經(jīng)驗 獲得超17個贊
這不是 SSH 協(xié)議。它可能類似于Apache HTTP 身份驗證。您可以遵循并嘗試本指南:使用 PHP 進行 HTTP 身份驗證
- 2 回答
- 0 關注
- 221 瀏覽
添加回答
舉報