简体   繁体   中英

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.

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. Get notified that he wants to download. Only the file is only 0 bytes.

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.

(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. You can also check the web server log to find out more.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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