PHP ftp_nlist is not working

余生长醉 提交于 2021-02-04 21:13:48

问题


$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");

if (@ftp_login($ftp_conn, $ftp_username, $ftp_userpass))
{
    $path = "./";
    $path1="./test";
    $file = "test.txt";
    $file_list = ftp_nlist($ftp_conn,$path);
}
// close connection
ftp_close($ftp_conn);

The above is the code which I am using. It is working fine for me on my Windows local machine, Windows server machine, Linux local machine, but somehow it fails on the Linux server machine. ftp_nlist returns false. Can someone tell me what might be the reason?

Any help appreciated. Thank you.


回答1:


Most typical cause of problems with ftp_nlist (or any other transfer command like ftp_get, ftp_put, ftp_rawlist) is that PHP defaults to the FTP active mode. And in 99% cases, one has to switch to the FTP passive mode, to make the transfer working. Use the ftp_pasv function.

$connect = ftp_connect($ftp) or die("Unable to connect to host");
ftp_login($connect, $username, $pwd) or die("Authorization failed");
// turn passive mode on
ftp_pasv($connect, true) or die("Passive mode failed");

See also my article on the active and passive FTP connection modes.



来源:https://stackoverflow.com/questions/49402376/php-ftp-nlist-is-not-working

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!