如何修复PHP curl错误CURLE_SSH(79)时使用sftp上传文件 [英] How to fix PHP curl error CURLE_SSH (79) when using sftp to upload file

查看:1243
本文介绍了如何修复PHP curl错误CURLE_SSH(79)时使用sftp上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图重现以下命令通过sftp在我的PHP应用程序上传文件:

I'm trying to reproduce the following command to upload a file via sftp on my PHP app:

curl -T /var/repo/file -u user:password sftp://server.com/folder/



<上面的命令工作正常(我不得不重新编译libcurl在我的ubuntu框,以使它工作,虽然)。但是,当我试图使用PHP的curl库时,对我来说并没有那么好。

The above commands works just fine (I had to recompile libcurl on my ubuntu box in order to make it work, though). However, when I tried to use PHP's curl library, things didn't go so well for me.

我使用的代码如下:

$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),我不知道如何解决。你遇到过这个问题吗?你是如何解决的?任何想法?

This gives back error 79: CURLE_SSH (79) which I dont know how to fix. Have you faced this problem? How did you fix it? Any ideas?

谢谢!

推荐答案

类型的错误从SSH层(libssh2)。如果您启用VERBOSE,您可能会看到更多详细信息。

It means libcurl got some kind of error from the "SSH layer" (libssh2). If you enable VERBOSE you might see further details.

您使用的是相当旧的libcurl和libssh2版本,因此您可以通过升级到现代版本。

You're using fairly old libcurl and libssh2 versions so it is not unthinkable that you can fix this problem simply by upgrading those to modern versions.

这篇关于如何修复PHP curl错误CURLE_SSH(79)时使用sftp上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆