php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75261 cURL sftp regression
Submitted: 2017-09-26 14:37 UTC Modified: 2017-09-26 15:01 UTC
From: b dot collin at immanens dot com Assigned:
Status: Closed Package: cURL related
PHP Version: 7.1.9 OS: Windows
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: b dot collin at immanens dot com
New email:
PHP Version: OS:

 

 [2017-09-26 14:37 UTC] b dot collin at immanens dot com
Description:
------------
I think that php 7.1 introduce a curl regression with the sftp protocol.

Below, a short script that work in php until 7.0.x, and produce an error message "Could not resolve host: xxxxx" where xxxxx is the username and not the host !

I check several version, php <= 7.0.x seem to be ok.
php 7.1.9, 7.1.10RC1 and 7.2.0RC2 are ko.

Test script:
---------------
$host = 'myhost.sftphost.test:22';
$user = 'myuser';
$password = 'mypassword';
$path = '/path/toexplore/';

$c = curl_init('sftp://'.$user.':'.$password.'@'.$host.$path);
curl_setopt($c, CURLOPT_PROTOCOLS, CURLPROTO_SFTP);
curl_setopt($c, CURLOPT_FTPLISTONLY, true);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($c);
print "curl message : ".curl_error($c)."\n";
print "data : ".var_dump($data);

Expected result:
----------------
If the config is ok, we should obtain the list of file from the sftp server whithout error.




Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-09-26 14:42 UTC] spam2 at rhsoft dot net
why don#t you use CURLOPT_USERPWD which is excatly designed for that usecase and leave curl_init() alone? that below is a snippet from a with 5.6, 7.0, 7.1 and 7.2 working wrapper library written long ago to replace pecl-ssh2

 public function connect(): bool
 {
  try
  {
   $options =
   [
    CURLOPT_PROTOCOLS => CURLPROTO_SFTP,
    CURLOPT_PORT => $this->port,
    CURLOPT_USERPWD => "$this->user:$this->pwd",
    CURLOPT_RETURNTRANSFER => 1,
   ];
   $this->curl = curl_init();
   curl_setopt_array($this->curl, $options);
   if($this->curl)
   {
    return true;
   }
   else
   {
    return false;
   }
  }
  catch(Throwable $e)
  {
   return false;
  }
 }
 [2017-09-26 14:59 UTC] b dot collin at immanens dot com
Ok.

I have test with CURLOPT_USERPWD, but don't change the CURLOPT_PORT... 

It work now. Either I fail my test, or the host:port syntax is not yet supported too.

The change seem to happen between 7.0.4 and 7.0.18

The new way work in 7.1.x

Thank you
 [2017-09-26 15:01 UTC] b dot collin at immanens dot com
-Status: Open +Status: Closed
 [2017-09-26 15:01 UTC] b dot collin at immanens dot com
It has to be done with a new way
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Feb 05 13:01:33 2025 UTC