0

Hello Community,
I need help using the ftp_nlist command, what i'm trying to do is look in a directory but the directory is two separate string (eg. "New folder") and it is saying there is nothing in there but there is i'm sure the problem is because the two separate stringed folder name. So is there a way to fix this.

Please help...

2
Contributors
7
Replies
13
Views
4 Years
Discussion Span
Last Post by joshl_1995
0
<?php
    $ftp_server = "SERVER";
    $ftp_user_name = "USERNAME";
    $ftp_user_pass = "PASSWORD";
    $conn_id = ftp_connect($ftp_server);
    $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
    ftp_pasv($conn_id, true);

    if (($conn_id) || ($login_result)) {
        $itemsArray = array();
        $items_list = ftp_nlist($conn_id, "MainDir/SubDir/New folder");
        foreach ($items_list as $item) {
            array_push($itemsArray, array("itemname" => $item));
        }
        unset($itemsArray['0']);
        unset($itemsArray['1']);
?>
<ul>
    <?php
        if (is_array($itemsArray)) {
            foreach ($itemsArray as $item) {
    ?>
    <li><?php echo $item['itemname'] ?></li>
    <?php
            }
        }
        else
            echo $itemsArray;
    ?>
</ul>
<?php
    } else {
        return "An error has occurred!";
    }

    ftp_close($conn_id);
?>
0

Yer i know it's the space but i want to know if there is a way to bypass that for it to work.

Anyway i tried adding that (ftp_chdir) but i'm getting this error:
Warning: ftp_chdir(): Can't change directory to MainDir/SubDir/New folder: No such file or directory in C:\wamp\www\CheckDir.php on line 11

This is the updated script using that method:

<?php
    $ftp_server = "SERVER";
    $ftp_user_name = "USERNAME";
    $ftp_user_pass = "PASSWORD";
    $conn_id = ftp_connect($ftp_server);
    $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
    ftp_pasv($conn_id, true);

    if (($conn_id) || ($login_result)) {
        $itemsArray = array();
        ftp_chdir($conn_id, "MainDir/SubDir/New folder");
        $items_list = ftp_nlist($conn_id, "");
        foreach ($items_list as $item) {
            array_push($itemsArray, array("itemname" => $item));
        }
        unset($itemsArray['0']);
        unset($itemsArray['1']);
?>
<ul>
    <?php
        if (is_array($itemsArray)) {
            foreach ($itemsArray as $item) {
    ?>
    <li><?php echo $item['itemname'] ?></li>
    <?php
            }
        }
        else
            echo $itemsArray;
    ?>
</ul>
<?php
    } else {
        return "An error has occurred!";
    }

    ftp_close($conn_id);
?>
1

Never mind i fixed it i didn't enter the correct name of the folder.
Thanks for your help.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.