I'm trying to shorten the time needed to download a file from SFTP by integrating SFTP and cURL.
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. Also SFTP defaults to 22 so it is bogus in your example. You can use:
$remote = "sftp://".$username.":".$password ."@".$host."/home/testfolder/saleskits/".$fn;
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.