# cUrl Getting SSRS (IIS6 NTLM)
###### tags: `curl` `php` `linux`
## Linux command
寫一個可以讓其他腳本可以使用的命令方式。
```bash
curl -s -f -L \
-o somefilename.subname \
-w "${http_cod}" \
--ntlm -u username:password \
"url_here"
```
* -s/--silent Silent mode. Don't output anything
* -f/--fail Fail silently (no output at all) on HTTP errors (H)
* -L/--location Follow Location: hints (H)
* -o/--output <file> Write output to <file> instead of stdout
* -w/--write-out <format> What to output after completion
* --ntlm Use HTTP NTLM authentication (H)
* -u/--user <user[:password]> Set server user and password
## PHP curl
```php
function getSQLServerReportServicesFile($url, $username, $password)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, true);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, false);
$result = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return $httpCode == 200 ? $result : false ;
}
$url = 'http://localhost/redirect_to_file';
$username = 'admin';
$password = 'passwd';
$output_filename = "test.pdf";
$fileData = getSQLServerReportServicesFile($url, $username, $password);
if($fileData)
{
$fp = fopen($output_filename, 'w');
fwrite($fp, $fileData);
fclose($fp);
}else{
echo "fail\n";
}
```