我可以用PHP连接到FTP服务器,但是即使在被动模式下也不能ftp_nlist [英] I can connect to an FTP server with PHP but can't ftp_nlist even with passive mode

查看:118
本文介绍了我可以用PHP连接到FTP服务器,但是即使在被动模式下也不能ftp_nlist的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题.我可以连接到FTP服务器,但是不能使用ftp_nlist.页面为白色,并且正在不断加载.

I have a problem. I can connect to a FTP server, but I can't use ftp_nlist. The page is white and loading endlessly.

这是我的代码:

$ftpStream = ftp_connect($host,$port);

if($ftpStream!=false)
{
    echo 'FTP Connected </br>';
    echo 'Hostname = ' . $host . '</br>';
    $login=ftp_login($ftpStream,$username,$password);
    if($login!=false)
    {
        echo 'Logged in </br>';
        $pasvMode = ftp_pasv($ftpStream, true);
        if($pasvMode!=false)
        {
            echo 'Entered passive mode </br>';
            // These lines aren't working:
            $listOfFiles = ftp_nlist($ftpStream,'.');
            var_dump($listOfFiles);
        }

        else
            echo 'ftp_pasv() fail </br>';
    }
    else
        echo 'Login failure </br>';
}
else
    echo 'ftp_connect fail </br>';

当我只尝试连接到该服务器时,一切正常,但是当我尝试ftp_nlist时,没有任何效果.当我在另一个FTP服务器上尝试此代码时,文件列表将正确显示.我真的不知道问题可能从哪里来.

When I'm only trying to connect to this server, everything works well, but when I'm trying to ftp_nlist, nothing works. When I try this code on another FTP server, the list of files is correctly displayed. I don't really know from where the problem could come.

我试图通过Web服务器上的命令行连接到FTP,结果如下:

I tried to connect to FTP from command-line on the web server and here are the results:

ftp> ls
Command okay.
150 File status okay; about to open data connection

这是从我的本地计算机连接时的FileZilla日志文件:

Here's the FileZilla log file, when connecting from my local machine:

2018-05-22 15:45:03 5180 1 Réponse : 230 User logged in, proceed.
2018-05-22 15:45:03 5180 1 Suivi : CFtpControlSocket::SendNextCommand()
2018-05-22 15:45:03 5180 1 Commande : USER Username@IPADRESS:PORT
2018-05-22 15:45:04 5180 1 Suivi : CFtpControlSocket::OnReceive()
2018-05-22 15:45:04 5180 1 Réponse : 331 User name okay, need password.
2018-05-22 15:45:04 5180 1 Suivi : CFtpControlSocket::SendNextCommand()
2018-05-22 15:45:04 5180 1 Commande : PASS ****
2018-05-22 15:45:08 5180 1 Suivi : CFtpControlSocket::OnReceive()
2018-05-22 15:45:08 5180 1 Réponse : 230 User logged in, proceed.
2018-05-22 15:45:08 5180 1 Suivi : CFtpControlSocket::SendNextCommand()
2018-05-22 15:45:08 5180 1 Commande : SYST
2018-05-22 15:45:09 5180 1 Suivi : CFtpControlSocket::OnReceive()
2018-05-22 15:45:09 5180 1 Réponse : 215 Windows_CE version 6.0.
2018-05-22 15:45:09 5180 1 Suivi : CFtpControlSocket::SendNextCommand()
2018-05-22 15:45:09 5180 1 Commande : FEAT
2018-05-22 15:45:10 5180 1 Suivi : CFtpControlSocket::OnReceive()
2018-05-22 15:45:10 5180 1 Réponse : 211-Features:
2018-05-22 15:45:10 5180 1 Réponse :   SIZE
2018-05-22 15:45:10 5180 1 Réponse : 211 End
2018-05-22 15:45:10 5180 1 Statut : Le serveur ne supporte pas les 
caractères non-ASCII.
2018-05-22 15:45:10 5180 1 Statut : Connecté 
2018-05-22 15:45:10 5180 1 Suivi : CFtpControlSocket::ResetOperation(0)
2018-05-22 15:45:10 5180 1 Suivi : CControlSocket::ResetOperation(0)
2018-05-22 15:45:10 5180 1 Suivi : Measured latency of 1145 ms
2018-05-22 15:45:10 5180 1 Statut : Récupération du contenu du dossier...
2018-05-22 15:45:10 5180 1 Suivi : CFtpControlSocket::SendNextCommand()
2018-05-22 15:45:10 5180 1 Suivi : CFtpControlSocket::ChangeDirSend()
2018-05-22 15:45:10 5180 1 Commande : PWD
2018-05-22 15:45:10 5180 1 Suivi : CFtpControlSocket::OnReceive()
2018-05-22 15:45:10 5180 1 Réponse : 257 "/"
2018-05-22 15:45:10 5180 1 Suivi : CFtpControlSocket::ResetOperation(0)
2018-05-22 15:45:10 5180 1 Suivi : CControlSocket::ResetOperation(0)
2018-05-22 15:45:10 5180 1 Suivi : 
CFtpControlSocket::ParseSubcommandResult(0)
2018-05-22 15:45:10 5180 1 Suivi : CFtpControlSocket::ListSubcommandResult()
2018-05-22 15:45:10 5180 1 Suivi : CFtpControlSocket::SendNextCommand()
2018-05-22 15:45:10 5180 1 Suivi : CFtpControlSocket::TransferSend()
2018-05-22 15:45:10 5180 1 Commande : TYPE I
2018-05-22 15:45:11 5180 1 Suivi : CFtpControlSocket::OnReceive()
2018-05-22 15:45:11 5180 1 Réponse : 200 Command okay.
2018-05-22 15:45:11 5180 1 Suivi : 
CFtpControlSocket::TransferParseResponse()
2018-05-22 15:45:11 5180 1 Suivi : CFtpControlSocket::SendNextCommand()
2018-05-22 15:45:11 5180 1 Suivi : CFtpControlSocket::TransferSend()
2018-05-22 15:45:11 5180 1 Commande : PASV
2018-05-22 15:45:12 5180 1 Suivi : CFtpControlSocket::OnReceive()
2018-05-22 15:45:12 5180 1 Réponse : 227 Entering Passive Mode 
(10,64,3,53,12,188)
2018-05-22 15:45:12 5180 1 Suivi : 
CFtpControlSocket::TransferParseResponse()
2018-05-22 15:45:12 5180 1 Suivi : CFtpControlSocket::SendNextCommand()
2018-05-22 15:45:12 5180 1 Suivi : CFtpControlSocket::TransferSend()
2018-05-22 15:45:12 5180 1 Commande : LIST
2018-05-22 15:45:12 5180 1 Suivi : CTransferSocket::OnConnect
2018-05-22 15:45:13 5180 1 Suivi : CFtpControlSocket::OnReceive()
2018-05-22 15:45:13 5180 1 Réponse : 150 File status okay; about to open 
data connection.
2018-05-22 15:45:13 5180 1 Suivi : 
CFtpControlSocket::TransferParseResponse()
2018-05-22 15:45:13 5180 1 Suivi : CFtpControlSocket::SendNextCommand()
2018-05-22 15:45:13 5180 1 Suivi : CFtpControlSocket::TransferSend()
2018-05-22 15:45:15 5180 1 Suivi : CTransferSocket::TransferEnd(1)
2018-05-22 15:45:15 5180 1 Suivi : CFtpControlSocket::TransferEnd()
2018-05-22 15:45:15 5180 1 Suivi : CFtpControlSocket::OnReceive()
2018-05-22 15:45:15 5180 1 Réponse : 226 Closing data connection. 
2018-05-22 15:45:15 5180 1 Suivi : 
CFtpControlSocket::TransferParseResponse()
2018-05-22 15:45:15 5180 1 Suivi : CFtpControlSocket::ResetOperation(0)
2018-05-22 15:45:15 5180 1 Suivi : CControlSocket::ResetOperation(0)
2018-05-22 15:45:15 5180 1 Suivi : 
CFtpControlSocket::ParseSubcommandResult(0)
2018-05-22 15:45:15 5180 1 Suivi : CFtpControlSocket::ListSubcommandResult()
2018-05-22 15:45:15 5180 1 Suivi : CFtpControlSocket::ResetOperation(0)
2018-05-22 15:45:15 5180 1 Suivi : CControlSocket::ResetOperation(0)
2018-05-22 15:45:15 5180 1 Statut : Contenu du dossier affiché avec succès

服务器是否可以禁止ftp_nlist()?

Is it possible for a server to forbid ftp_nlist() ?

对不起,我的英语不好,谢谢您今后的回答.

Sorry for my bad English, and thanks in advance for your future answers.

推荐答案

您的虚拟主机提供商似乎阻止了与FTP服务器的传出数据连接.

It looks like your web hosting provider blocks outgoing data connections to the FTP server.

您可以尝试使用活动模式(删除ftp_pasv呼叫).但是,如果它们禁止传出连接,则它们不太可能允许传入连接(活动模式需要).

You can try using an active mode (remove the ftp_pasv call). But it's quite unlikely that they would allow incoming connections (needed for the active mode), if they forbid outgoing connections.

有关某些背景知识,请参阅我关于被动和主动FTP模式所需的网络设置的文章 -尽管您自己无能为力.您需要联系您的提供商.

For some background, see my article about network setup needed for passive and active FTP modes - Though nothing you can do about it yourself. You need to contact your provider.

这篇关于我可以用PHP连接到FTP服务器,但是即使在被动模式下也不能ftp_nlist的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆