cURL sftp public key authentication fails quot;Callback Errorquot;(cURL sftp 公钥认证失败“回调错误)
问题描述
我有一些 php 代码可以很好地使用 cURL 将文件上传到仅使用用户 & 的主机.密码 ftp,现在我必须上传到只允许公钥身份验证的服务器并收到错误:* SSH 公钥身份验证失败:回调返回错误"
I have some php code which works well uploading files using cURL to hosts which are simply using user & password ftp, now I have to upload to a server which only allows public key auth and am getting the error: "* SSH public key authentication failed: Callback returned error"
我的密钥有问题,因为它们的格式不正确,但后来将它们放入正确的单行格式,这阻止了非 base64 编码"错误.我在网上找不到太多关于这个回调错误的帮助.
I had a problem with the keys as they were not in the right format, but have since put them in the correct single line format and this stopped the "not base64 encoded" errors. I can't find much help on this callback error online.
我的代码如下.
$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_URL, 'sftp://user:@12.12.12.12:22/testfile.gz');
curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_SFTP);
curl_setopt($ch, CURLOPT_SSH_PUBLIC_KEYFILE,'C:keyspublic.pub');
curl_setopt($ch, CURLOPT_SSH_PRIVATE_KEYFILE,'C:keysprivate.ppk');
curl_setopt($ch, CURLOPT_SSH_HOST_PUBLIC_KEY_MD5,'2acfe24108c37a276a93ac3398a5oe8f');
curl_setopt($ch, CURLOPT_SSH_AUTH_TYPES,CURLSSH_AUTH_PUBLICKEY);
curl_setopt($ch, CURLOPT_UPLOAD, 1);
$fp = fopen($localfile, 'r');
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile));
$sR = curl_exec ($ch);
这是运行测试的输出
* About to connect() to 12.12.12.12 port 22 (#0)
* Trying 12.12.12.12...
* connected
* Connected to 12.12.12.12 (12.12.12.12) port 22 (#0)
* SSH MD5 fingerprint: ebbc61b886c798b25073c912833ffers
* SSH authentication methods available: publickey
* Using ssh public key file C:keyspublic.pub
* Using ssh private key file C:keysprivate.ppk
* SSH public key authentication failed: Callback returned error
* Authentication failure
* Closing connection #0
任何帮助表示赞赏
推荐答案
当你的 libssh2 是用 libgcrypt 构建时,有一些情况(基于 debian 的发行版).其中,使用 PEM 编码的私钥文件:
There are cases (debian-based distros) when your libssh2 is built with libgcrypt. In those, use PEM-encoded private key file:
$ openssl rsa -in ~/.ssh/id_rsa -outform pem > id_rsa.pem
这篇关于cURL sftp 公钥认证失败“回调错误"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:cURL sftp 公钥认证失败“回调错误"
基础教程推荐
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 在多维数组中查找最大值 2021-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01