|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 21:00:01 2025 UTC |
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; } }