2011-11-08 57 views
2

我似乎無法使用cURL通過SFTP下載文件。使用SFTP和cURL獲取文件

$c = curl_init("sftp://$user:[email protected]/someserver.com/$filename"); 
    $fh = fopen($filename, 'w') or die($php_errormsg); 
    curl_setopt($c, CURLOPT_PROTOCOLS, CURLPROTO_SFTP); 
    curl_setopt($c, CURLOPT_FILE, $fh); 
    curl_exec($c); 
    curl_close($c); 

我做錯了什麼?非常感謝您的幫助

米歇爾

+5

'curl_error()'可以用來查看錯誤 –

+1

你得到的錯誤是什麼?如果它是空白屏幕,請在代碼中添加一些echo或printf語句,並查看哪條線路無法正常工作。 – ssamuel

回答

1

在此服務器上使用的libcurl中必須有支持SFTP的編譯。縱觀返回代碼會告訴你是否它支持與否。如果沒有,那麼你必須要求服務器管理員升級libcurl。

2

是的,你有一個/繼續你的域名。

$c = curl_init("sftp://$user:[email protected]/$filename"); 
$fh = fopen($filename, 'w') or die($php_errormsg); 
curl_setopt($c, CURLOPT_PROTOCOLS, CURLPROTO_SFTP); 
curl_setopt($c, CURLOPT_FILE, $fh); 
curl_exec($c); 
curl_close($c); 
+0

;)感謝您爲我節省了研究成果 – ppostma1