|  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
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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: wowkise at gmail dot com
New email:
PHP Version: OS:


 [2013-01-18 15:28 UTC] wowkise at gmail dot com
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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-01-22 15:57 UTC]
-Assigned To: +Assigned To: dtajchreber
 [2013-01-22 15:57 UTC]
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. 

 [2017-10-24 07:10 UTC]
-Status: Assigned +Status: Open -Assigned To: dtajchreber +Assigned To:
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 30 20:01:30 2024 UTC