php - uploading with SFTP : CURLOPT_SSLKEY is not used -


i have upload via sftp files server another

here sftp() function :

function transfert_curl_sftp($local_filename, $distant_filename, $host_destination, $user_destination,$pubkey_filename,$privkey_filename,$port) { if ( !extension_loaded('curl') ) return 'no_curl_extension'; $distant_filename = ltrim($distant_filename,'/');  $fp = fopen($local_filenam, 'r'); $sftp_server = $host_destination.'/'.$distant_filename; $curl = curl_init(); curl_setopt($curl, curlopt_upload, true); curl_setopt($curl, curlopt_header, true); curl_setopt($curl, curlopt_verbose, true); curl_setopt($curl, curlopt_returntransfer, true); curl_setopt($curl, curlopt_protocols, curlproto_sftp);  curl_setopt($curl, curlopt_noprogress, false); curl_setopt($curl, curlopt_followlocation, true);  $trace = tempnam( dirname($local_filenam),'temp_curl_' ); $fptrace = fopen($trace, 'w'); curl_setopt($curl, curlopt_file, $fptrace); curl_setopt($curl, curlopt_stderr, $fptrace);  curl_setopt($curl, curlopt_url, 'sftp://@'.$sftp_server); curl_setopt($curl, curlopt_port, $port); curl_setopt($curl, curlopt_userpwd, $user_destination.':'); curl_setopt($curl, curlopt_ssh_public_keyfile, $pubkey_filename); curl_setopt($curl, curlopt_sslengine, ''); curl_setopt($curl, curlopt_sslkey, $privkey_filename); curl_setopt($curl, curlopt_sslkeypasswd, '');  curl_setopt($curl, curlopt_infilesize, filesize($local_file)); curl_setopt($curl, curlopt_infile, $fp);  $info = curl_getinfo($curl); $start_error_no = curl_errno($curl); $valid_operation = curl_exec($curl);    $final_error_no = curl_errno($curl); curl_close($curl); fclose($fp); fclose($fptrace);  echo '<pre>trace:',file_get_contents($trace),'<hr>'; var_dump($start_error_no,$valid_operation,$final_error_no);  return true; } 

the file never uploaded :-(

when trace file see * ssh authentication methods available: publickey,password * using ssh public key file /var/www/xxx/yyy/upload/dsa-zzz.pub * using ssh private key file id_dsa * ssh public key authentication failed: callback returned error * think 'curlopt_sslkey' parameter not set... key files ok reading...

is php bug ? or fail writing ?

sftp protocol uses ssh2 secure connection, need provide ssh private key, not ssl's one. ssh , ssl 2 distinct ways secure connection (more details difference).

so should replace :

curl_setopt($curl, curlopt_sslengine, ''); curl_setopt($curl, curlopt_sslkey, $privkey_filename); curl_setopt($curl, curlopt_sslkeypasswd, ''); 

by :

curl_setopt($curl, curlopt_ssh_auth_types, curlssh_auth_publickey); curl_setopt($curl, curlopt_ssh_public_keyfile, $pubkey_filename); // did curl_setopt($curl, curlopt_ssh_private_keyfile, $privkey_filename); curl_setopt($curl, curlopt_keypasswd, ''); 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -