php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #54665 CURLOPT_SSH_PUBLIC_KEYFILE and CURLOPT_SSH_PRIVATE_KEYFILE are not documented
Submitted: 2011-05-05 09:20 UTC Modified: 2013-07-30 03:42 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: bhaskarna at yahoo dot com Assigned: yohgaki (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2011-05-05 09:20 UTC] bhaskarna at yahoo dot com
Description:
------------
CURLOPT_SSH_PUBLIC_KEYFILE and CURLOPT_SSH_PRIVATE_KEYFILE are not documented. They are useful when we require to scp or sftp a file thru curl api.

I could achieve successful sftp using above said curl_setopts 



Test script:
---------------
<?php
      $certPath="/home/y/conf/yapache/ssh-keys/akamai.id_rsa.pub";
     $keyPath="/home/y/conf/yapache/ssh-keys/akamai.id_rsa";
      error_reporting(E_ALL);
      ini_set('display_errors', 1);
      $ch = curl_init();
      $localfile = 'scp-small-file.txt';
      $fp = fopen($localfile, 'r');
      curl_setopt($ch, CURLOPT_URL, 'sftp://@72.246.194.54/21996/'.$localfile);
      curl_setopt($ch, CURLOPT_UPLOAD, 1);
      curl_setopt($ch,CURLOPT_VERBOSE, 1);
      curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_SFTP);
      curl_setopt($ch, CURLOPT_SSH_PUBLIC_KEYFILE, $certPath);
      curl_setopt($ch, CURLOPT_SSH_PRIVATE_KEYFILE, $keyPath);
      curl_setopt($ch, CURLOPT_USERPWD,'sshacs');
      curl_setopt($ch, CURLOPT_INFILE, $fp);
      curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile));
      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;
?>


* About to connect() to 72.246.194.54 port 22 (#0)
*   Trying 72.246.194.54... * connected
* Connected to 72.246.194.54 (72.246.194.54) port 22 (#0)
* SSH authentication methods available: publickey
* Using ssh public key file /home/y/conf/yapache/ssh-keys/akamai.id_rsa.pub
* Using ssh private key file /home/y/conf/yapache/ssh-keys/akamai.id_rsa
* Initialized SSH public key authentication
* Authentication complete
* Connection #0 to host 72.246.194.54 left intact
* Closing connection #0
File uploaded succesfully. 0



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-05-05 09:50 UTC] php dot proging at gmail dot com
also, when you change to CURLPROTO_SCP:

$ diff -u b.php a.php 
--- b.php       2011-05-05 07:42:56.000000000 +0000
+++ a.php       2011-05-05 07:42:44.000000000 +0000
@@ -6,10 +6,10 @@
       $ch = curl_init();
       $localfile = 'scp-small-file.txt';
       $fp = fopen($localfile, 'r');
-      curl_setopt($ch, CURLOPT_URL, 'sftp://@72.246.194.54/21996/'.$localfile);
+      curl_setopt($ch, CURLOPT_URL, 'scp://@72.246.194.54/21996/'.$localfile);
       curl_setopt($ch, CURLOPT_UPLOAD, 1);
       curl_setopt($ch,CURLOPT_VERBOSE, 1);
-      curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_SFTP);
+      curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_SCP);
       curl_setopt($ch, CURLOPT_SSH_PUBLIC_KEYFILE, $certPath);
       curl_setopt($ch, CURLOPT_SSH_PRIVATE_KEYFILE, $keyPath);
       curl_setopt($ch, CURLOPT_USERPWD,'sshacs');


it doesn't work and throws the following error:

* About to connect() to 72.246.194.54 port 22 (#0)
*   Trying 772.246.194.54... * connected
* Connected to t72.246.194.54 (772.246.194.54) port 22 (#0)
* SSH authentication methods available: publickey,keyboard-interactive
* Using ssh public key file /home/y/conf/yapache/ssh-keys/akamai.id_rsa.pub
* Using ssh private key file /home/y/conf/yapache/ssh-keys/akamai.id_rsa
* Initialized SSH public key authentication
* Authentication complete
* SSH CONNECT phase done
* scp: '/scp-small-file.txt': No such file or directory

* Connection #0 to host 72.246.194.54 left intact
* Closing connection #0
File upload error. 79
 [2011-05-05 09:56 UTC] bhaskarna at yahoo dot com
Prerequisite to run this:
please create a text file with name: scp-small-file.txt

even i found scp doesn't work but sftp works so, atleast we should document it so that people will not get wondered on - what next after setting "CURLPROTO_SFTP" as the CURLOPT_PROTOCOLS. (Note that, CURLPROTO_SFTP is documented but the respective prerequisites like setting 
CURLOPT_SSH_PUBLIC_KEYFILE and CURLOPT_SSH_PRIVATE_KEYFILE 
is not documented.
 [2012-02-15 14:03 UTC] joris@php.net
I have added the following constants to the CURL documentation:
CURLSSH_AUTH_NONE, CURLSSH_AUTH_PUBLICKEY, CURLSSH_AUTH_PASSWORD, CURLSSH_AUTH_HOST, CURLSSH_AUTH_KEYBOARD, CURLSSH_AUTH_DEFAULT, CURLOPT_SSH_AUTH_TYPES, CURLOPT_KEYPASSWD, CURLOPT_SSH_PUBLIC_KEYFILE, CURLOPT_SSH_PRIVATE_KEYFILE and CURLOPT_SSH_HOST_PUBLIC_KEY_MD5.

It will take some time for the documentation to be updated with this changes.
 [2013-07-30 03:42 UTC] yohgaki@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: yohgaki
 [2013-07-30 03:42 UTC] yohgaki@php.net
According to comment and doc page, this issue is fixed.

http://www.php.net/manual/en/curl.constants.php
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 27 23:01:30 2024 UTC