php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73924 ssh2_sftp wrapper issue
Submitted: 2017-01-12 23:33 UTC Modified: 2021-02-09 15:02 UTC
Votes:3
Avg. Score:4.3 ± 0.9
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: ziggi at ziggi dot pl Assigned: cmb (profile)
Status: Closed Package: ssh2 (PECL)
PHP Version: 7.1.0 OS: Windows 10 x64
Private report: No CVE-ID: None
 [2017-01-12 23:33 UTC] ziggi at ziggi dot pl
Description:
------------
'php_ssh2-1.0-7.1-nts-vc14-x64' is erratic compared with 'php_ssh2-1.0-7.0-nts-vc14-x64'.

At least this is working wrong in case of the PHP 7.1 release:

is_dir('ssh2.sftp://' . ssh2_sftp(ssh2_connect($host, $port)) . '$absolute_path_to_remote_directory')

Resolution:

In case of a valid folder with appropriate permissions:

php_ssh2-1.0-7.0-nts-vc14-x64 returns 'true' while
php_ssh2-1.0-7.1-nts-vc14-x64 returns' false'

This has been found while using PHPLOY (https://github.com/banago/PHPloy) on my Windows 10 x64 Pro system using PHP 7.0 (NTS) x64 and PHP 7.1 (NTS) x64 - both VS14 compliations.

Test script:
---------------
is_dir('ssh2.sftp://' . ssh2_sftp(ssh2_connect($host, $port)) . '$absolute_path_to_remote_directory');


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-02-27 14:05 UTC] andreas dot krause at webular dot de
Exakt same Issue with PHP 7.1.2 (SSH-2.0-libssh2_1.4.2)

Worked fine with php 5.6.23 (SSH-2.0-libssh2_1.4.2)

System is a Debian 7

my workaround is:

$streamCheck = ssh2_exec($this->getSshConnection(), 'test -d '.escapeshellarg($folder).' && echo 1 || echo 0');
stream_set_blocking($streamCheck, true);
$streamCheck_out = ssh2_fetch_stream($streamCheck, SSH2_STREAM_STDIO);

before it was: is_dir('ssh2.sftp://'.$this->getSftpConnection().$folder) -> this returns now always false
 [2019-02-07 21:49 UTC] memso at memso dot net
You must use intval on the result from ssh2_sftp now, per http://php.net/manual/en/function.ssh2-sftp.php

So instead, use this:
$ssh2 = ssh2_connect($host, $port);
$sftp = ssh2_sftp($ssh2);
is_dir('ssh2.sftp://' . intval($sftp) . $absolute_path_to_remote_directory)
 [2021-02-09 15:02 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2021-02-09 15:02 UTC] cmb@php.net
This is supposed to be fixed as of ssh2 1.1.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Oct 13 21:01:28 2024 UTC