简体   繁体   English

PHP Curl SFTP 下载在本地工作但不在服务器上

[英]PHP Curl SFTP download working local but not on the server

I've picked bits of code here and there to make sure I can download a file directly in the browser from an sFtp server.我在这里和那里挑选了一些代码,以确保我可以从 sFtp 服务器直接在浏览器中下载文件。

When I run the script locally it works perfectly, it downloads the file just fine.当我在本地运行脚本时,它运行良好,它下载文件就好了。 When I upload it on my ubuntu 20.04 server and go to the url in the browser.当我将它上传到我的 ubuntu 20.04 服务器和 go 到浏览器中的 url 时。 Get notified that he wants to download.得到通知他要下载。 Only the file is only 0 bytes.只有文件只有0字节。

The script:剧本:

header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary"); 
header("Content-disposition: attachment; filename=\"demo.pdf\""); 

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "sftp://".$host."/demo.pdf");
curl_setopt($curl, CURLOPT_PROTOCOLS, CURLPROTO_SFTP);
curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");
curl_exec($curl);
curl_close($curl);

Curl PHP extension is installed on the server. Curl PHP 扩展安装在服务器上。

(Edit) Fix (i think): (编辑)修复(我认为):

When i add the following lines.当我添加以下行时。 It will work:它将起作用:

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);

Please check your php.ini settings and confirm that curl_exec function isn't disabled there.请检查您的 php.ini 设置并确认 curl_exec function 未在此处禁用。 You can also check the web server log to find out more.您还可以查看 web 服务器日志以了解更多信息。

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM