简体   繁体   English

尝试使用PHP中的cURL从SFTP服务器下载文件时,权限被拒绝

[英]Permission denied when tring to download file from SFTP server using cURL in PHP

I'm trying to shorten the time needed to download a file from SFTP by integrating SFTP and cURL. 我正在尝试通过集成SFTP和cURL来缩短从SFTP下载文件所需的时间。

My codes are as below: 我的代码如下:

$host = "192.168.1.1";
$username = "testuser";
$password = "testpass";
$fn = 'testfile.zip';
$remote = "sftp://".$username.":".$password ."@".$host.":22/home/testfolder/saleskits/".$fn;

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $remote); #input
curl_setopt($curl, CURLOPT_PROTOCOLS, CURLPROTO_SFTP);
curl_exec($curl);
if (!curl_errno($curl)) {
    $info = curl_getinfo($curl);
    echo 'Took ', $info['total_time'], ' seconds to send a request to ', $info['url'], "\n";
}
else{
    echo 'Curl error: ' . curl_error($curl);
}
curl_close($curl);

and the output is "Curl error: Could not open remote file for reading: Permission denied ". 并且输出为“卷曲错误:无法打开远程文件进行读取:权限被拒绝”。 How can I get passed the permission or change the permission of the file? 如何获得许可或更改文件的许可?

The cURL URL does not contain port according to documentation. 根据文档, cURL URL不包含端口。 Also SFTP defaults to 22 so it is bogus in your example. 另外,SFTP默认为22,因此在您的示例中是虚假的。 You can use: 您可以使用:

$remote = "sftp://".$username.":".$password ."@".$host."/home/testfolder/saleskits/".$fn;

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

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