SFTP not supported error with PHP & cURL
Posted
by
Bad Programmer
on Stack Overflow
See other posts from Stack Overflow
or by Bad Programmer
Published on 2012-06-26T22:12:43Z
Indexed on
2012/06/27
3:16 UTC
Read the original article
Hit count: 148
I followed the advice from this Stack Overflow question thread, but I keep hitting a snag.
I am receiving the following error message: Unsupported protocol: sftp
Here is my code:
$ch = curl_init();
if(!$ch)
{
$error = curl_error($ch);
die("cURL session could not be initiated. ERROR: $error."");
}
$fp = fopen($docname, 'r');
if(!$fp)
{
$error = curl_error($ch);
die("$docname could not be read.");
}
curl_setopt($ch, CURLOPT_URL, "sftp://$user_name:$user_pass@$server:22/$docname");
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_SFTP);
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($docname));
//this is where I get the failure
$exec = curl_exec ($ch);
if(!$exec)
{
$error = curl_error($ch);
die("File $docname could not be uploaded. ERROR: $error.");
}
curl_close ($ch);
I used the curl_version() function to see my curl information, and found that sftp doesn't seem to be in the array of supported protocols:
[version_number] => 462597
[age] => 2
[features] => 1597
[ssl_version_number] => 0
[version] => 7.15.5
[host] => x86_64-redhat-linux-gnu
[ssl_version] => OpenSSL/0.9.8b
[libz_version] => 1.2.3
[protocols] => Array
(
[0] => tftp
[1] => ftp
[2] => telnet
[3] => dict
[4] => ldap
[5] => http
[6] => file
[7] => https
[8] => ftps
)
Is this a matter of my version of cURL being outdated, or is the SFTP protocol simply not supported at all?
Any advice is greatly appreciated.
© Stack Overflow or respective owner