php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71376 stat() related functions fail on ssh2.sftp urls
Submitted: 2016-01-14 23:10 UTC Modified: 2017-10-24 06:48 UTC
Votes:35
Avg. Score:4.7 ± 0.7
Reproduced:32 of 32 (100.0%)
Same Version:17 (53.1%)
Same OS:15 (46.9%)
From: dougal at gunters dot org Assigned: langemeijer (profile)
Status: Closed Package: ssh2 (PECL)
PHP Version: 7.0.2 OS: Linux (Ubuntu 14.04)
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: dougal at gunters dot org
New email:
PHP Version: OS:

 

 [2016-01-14 23:10 UTC] dougal at gunters dot org
Description:
------------
Trying to use functions like is_dir(), is_file(), or any other stat() based function is failing when using an ssh2.sftp resource. Sample warning:

PHP Warning:  filemtime(): stat failed for ssh2.sftp://Resource id #5/etc/issue.net in /home/dougal/test/ssh.php on line 54

Using PHP 7.0.1, php-ssh2 0.12-dev

The same code works fine on a system running PHP 5.6.14 and php-ssh2 0.12


Test 

Test script:
---------------
<?php
$user = "myusername";
$pass = "mypassword";
$host = "localhost";
$path = "/some/file/that/exists";

$session = ssh2_connect($host, 22);
ssh2_auth_password($session, $user, $pass);
$sftp = ssh2_sftp($session);

$sshpath = "ssh2.sftp://$sftp$path";

$stat = stat($path); // works
$statpath = stat($sshpath); // doesn't work
$stat_sftp = ssh2_sftp_stat($sftp, $path); // works

$stream = fopen($sshpath, 'r');
$stat_stream = fstat($stream); // works


Expected result:
----------------
There should be no warnings. stat(), is_file(), is_dir(), etc. should return correct results for $sshpath.


Actual result:
--------------
PHP Warning:  stat(): stat failed for ssh2.sftp://Resource id #5/home/dougal/testfile.txt in /home/dougal/test/ssh-test.php on line 13

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-01-16 18:05 UTC] seander@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: seander
 [2016-01-16 18:05 UTC] seander@php.net
Hi!
I am the one who ported SSH2 (incorrectly) to PHP 7. Working on a fix for this now, and a test to go with it. Thanks for reporting this
 [2016-01-16 18:27 UTC] dougal at gunters dot org
Great @seander, thanks for the update, looking forward to the update.

Oh, and I found another related ticket:
https://bugs.php.net/bug.php?id=71047

Pretty positive that's the same issue.
 [2016-05-17 11:39 UTC] paul at incodia dot com
Hi @seander, many thanks for your work on this.  Do you know if/when it's likely to be resolved?  I'm just updating systems to PHP7 and have come across this issue.  Using PHP 7.0.6-dev, Ubuntu 14.04, libssh2-php 0.12-1build1 amd64
 [2017-02-06 19:49 UTC] langemeijer@php.net
This might well be fixed with this commit:

https://github.com/php/pecl-networking-ssh2/commit/17680cf039f0cfac53b5a2531fdb715b95e9cc42

Could you try current master and see if the problem is solved?
 [2017-02-06 19:58 UTC] langemeijer@php.net
-Assigned To: seander +Assigned To: langemeijer
 [2017-03-21 12:21 UTC] stian at strandem dot net
Hi,

I can confirm that this file_exists() on ssh2.sftp paths starts to behave correctly when using code from master.

Solved Wordpress upgrades in php7 over ssh2 for me, as described here:
https://core.trac.wordpress.org/ticket/35517

So I think you can consider this solved :)
 [2017-10-24 06:48 UTC] kalle@php.net
-Status: Assigned +Status: Closed
 [2018-06-18 02:32 UTC] quinn at strangecode dot com
This same bug appears to be exist also in PHP 5.6.36. Is there a separate ticket for that version? Which PHP version in the 5.6 channel will have the fix?

I'm having the problem, and found this person too: https://core.trac.wordpress.org/ticket/41030
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Nov 24 16:01:31 2024 UTC