PHP和cURL不支持SFTP错误
发布时间:2020-12-13 17:12:27 所属栏目:PHP教程 来源:网络整理
导读:我遵循了 this Stack Overflow question thread的建议,但我一直在努力. 我收到以下错误消息:不支持的协议:sftp 这是我的代码: $ch = curl_init();if(!$ch){ $error = curl_error($ch); die("cURL session could not be initiated. ERROR: $error."");}$fp
我遵循了
this Stack Overflow question thread的建议,但我一直在努力.
我收到以下错误消息:不支持的协议:sftp 这是我的代码: $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); 我使用curl_version()函数来查看我的curl信息,发现sftp似乎不在支持的协议数组中: [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 ) 这是我的cURL版本过时的问题,还是根本不支持SFTP协议? 任何意见是极大的赞赏. 解决方法
也许尝试使用
phpseclib,a pure PHP SFTP implementation.例如
<?php include('Net/SFTP.php'); $sftp = new Net_SFTP('www.domain.tld'); if (!$sftp->login('username','password')) { exit('Login Failed'); } // puts a three-byte file named filename.remote on the SFTP server $sftp->put('filename.remote','xxx'); ?> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |