我试图重现下面的命令来上传通过SFTP文件在我的PHP应用程序来解决PHP卷曲的错误CURLE_SSH(79):以上如何使用SFTP时上传文件
curl -T /var/repo/file -u user:password sftp://server.com/folder/
命令作品很好(我必须在我的ubuntu盒子上重新编译libcurl才能使它工作)。但是,当我尝试使用PHP的curl库时,事情对我来说并没有那么好。
我正在使用的代码如下:
$ch = curl_init();
$localfile = 'file';
$fp = fopen($localfile, 'r');
curl_setopt($ch, CURLOPT_URL, 'sftp://server.com/folder/');
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_USERPWD, 'user:password');
curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_SFTP);
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_exec ($ch);
$error_no = curl_errno($ch);
curl_close ($ch);
if ($error_no == 0) {
$error = 'File uploaded succesfully.';
} else {
$error = 'File upload error.';
}
echo $error.' '.$error_no;
这还给错误79:CURLE_SSH(79),我不知道如何解决。你有没有遇到这个问题?你怎么修好它的?有任何想法吗?
谢谢!
你在什么操作系统上使用什么curl版本和什么libssh2版本?您正在使用哪个PHP版本以及PHP curl扩展的哪个版本? – hakre 2012-04-18 16:15:09
curl 7.19.7(x86_64-pc-linux-gnu)libcurl/7.19.7 OpenSSL/0.9.8k zlib/1.2.3.3 libidn/1.15 libssh2/1.2.2 协议:tftp ftp telnet dict ldap ldaps http文件https ftps scp sftp 功能:GSS协商国际化域名IPv6大文件NTLM SSL libz – dabito 2012-04-18 17:46:54
通过ubuntu 11.10与PHP 5 ..生病让我回到你的curl扩展版本 – dabito 2012-04-18 17:47:24