开发者

PHP: list files on ftp server?

开发者 https://www.devze.com 2023-01-06 18:48 出处:网络
can\'开发者_如何学编程t get it done! <!DOCTYPE html> <html lang=\"en\"> <head>

can'开发者_如何学编程t get it done!

<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>FTP Download</title>
</head>
<body>
    <?php

    set_time_limit(300);//for setting 
    $path='/userupload';
    $ftp_server='202. …';
    $ftp_server_port="21";
    $ftp_user_name='al…';
    $ftp_user_pass="mypassword";

    // set up a connection to ftp server
    $conn_id = ftp_connect($ftp_server, $ftp_server_port); 
    // login with username and password
    $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

    // check connection and login result
    if ((!$conn_id) || (!$login_result)) { 
        echo "Fail</br>";
    } else {
        echo "Success</br>";
        // enabling passive mode
        ftp_pasv( $conn_id, true );
        // get contents of the current directory
        $contents = ftp_nlist($conn_id, $path);
        // output $contents
        var_dump($contents);
    }

    // close the FTP connection
    ftp_close($conn_id);

    ?>
</body>
</html>

any idea what I'm doing wrong? it always returns "Success bool(false)"! So the connection is working, however the files won't get listed. Any ideas?

regards


what I'm doing wrong?

you've lack of debugging.

checking only connect result is not enough. have to check every operation as well.

did ftp_pasv() worked?
is there /userupload dir?


what Shrapnel is saying is you can have more debugging than youve got if you've got

//enabling passive mode ftp_pasv( $conn_id, true );

then you can use if(ftp_pasv( $conn_id, true )){// it worked :) }else{// it didnt work :( }

But what I think is wrong is your path, if the home folder of your ftp user lands them inside here /useruploads/im here then to list the files your path should be $path='/'; otherwise what your telling the ftp to do is list the directory "useruploads/useruploads" which isnt going to exist.

0

精彩评论

暂无评论...
验证码 换一张
取 消