php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #64024 ftp_dir_exists()
Submitted: 2013-01-18 15:28 UTC Modified: 2017-10-24 07:10 UTC
Votes:4
Avg. Score:3.5 ± 0.9
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: wowkise at gmail dot com Assigned:
Status: Open Package: FTP related
PHP Version: Irrelevant OS: Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: wowkise at gmail dot com
New email:
PHP Version: OS:

 

 [2013-01-18 15:28 UTC] wowkise at gmail dot com
Description:
------------
I think PHP needs proper way to check if the FTP directory exists, right now there is no correct way to do it other then using ftp_chdir/is_dir and check the results which produce E_WARNING if the directory doesn't exists.

there is also is_dir() function which require that you re-authenticate just to check if the directory exists and if you have to check multiple directories you have to re-authenticate each time.

i hacked this function in "test script" just to bypass the E_WARNING 

Test script:
---------------
function dir_exists2($conn, $dir) {
    $orginal = $dir;
    if ( !$conn )
        return false;

    if ( substr($dir, -1) === '/' )
        $dir = substr($dir, 0, strlen($dir)-1);

    $dir    = substr($dir, 0, strlen($dir)-strlen(strrchr($dir,'/')));

    $res  = ftp_nlist($conn, '-dF '. $dir);
    if ( isset($res) AND is_array($res) ) {
            foreach ($res as $key => $value) {
                if ($value === $orginal)
                    return true;
            }
        }
        return false;
    }

Expected result:
----------------
true if directory exists and false if it does not exists.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-01-22 15:57 UTC] dtajchreber@php.net
-Assigned To: +Assigned To: dtajchreber
 [2013-01-22 15:57 UTC] dtajchreber@php.net
If the ftpd supports MLST, you can use ftp_raw() to send the command. But I'd also 
like to see this implemented as well. 

[1] http://tools.ietf.org/html/rfc3659#page-23
[2] http://us1.php.net/ftp_raw
 [2017-10-24 07:10 UTC] kalle@php.net
-Status: Assigned +Status: Open -Assigned To: dtajchreber +Assigned To:
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Oct 14 07:01:29 2024 UTC