我无法在使用PHP的FTP服务器上工作,但连接正常,但无法获取文件或其他东西.它与FileZilla一起使用 [英] I can't work on a FTP server with PHP, the connection works, but I can't get files, or other things. It works with FileZilla

查看:101
本文介绍了我无法在使用PHP的FTP服务器上工作,但连接正常,但无法获取文件或其他东西.它与FileZilla一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题.我正在使用PHP连接到FTP服务器,以便获取存储在服务器上的文件列表.我可以正确连接(使用ftp_connect,也可以使用ftp_login登录,我也使用了被动模式).当我刚连接时,一切都可以正常工作.当我在我的代码中添加ftp_nlist或其他操作时,它不起作用.页面正在不断加载.我可以使用FileZilla连接并在服务器上工作,但是我想使它自动化.它适用于FileZilla,但不适用于PHP,您能帮我吗?

I have an issue. I'm using PHP to connect to a FTP server, in order to get the list of files stored on the server. I can connect properly (with ftp_connect, and also login with ftp_login, I used passive mode too). Everthing works when I'm just connecting. When I add ftp_nlist or another action to my code, it doesn't work. The page is just loading endlessly. I can use FileZilla to connect and work on the server, but I want to automate this. It works with FileZilla but not with PHP, can you help me ?

它试图连接到另一个FTP服务器,并且运行良好.我可以得到文件列表.但是我无法使用所需的服务器.

It tried to connect to another FTP server and it works well. I can get the file list. But I can't with the server that I want.

这是我的代码:

$ftpStream=ftp_connect($hostname,$port);
if($ftpStream==false) 
    echo 'No connection </br>';
else { 
    echo 'Connected </br>';
    if(ftp_login($ftpStream,$ftpUsername,$ftpPassword)!=false) { 
        echo 'Logged </br>';
            if(ftp_pasv($ftpStream,true)!=false) 
                echo 'Passive mode on </br>'; 
        $list=ftp_nlist($ftpStream,'.'); 
    } 
    else echo 'Wrong ftpUsername or ftpPassword</br>'; 
}

我检查了文件权限,可以读取,写入和执行,所以问题不出于我认为的文件权限.

I checked the files permissions, I can read, write, and execute, so the problem doesn't come from file permissions I think.

这是日志文件:

2018-05-04 09:28:10 248 1 Suivi : CControlSocket::SendNextCommand()
2018-05-04 09:28:10 248 1 Suivi : CFtpLogonOpData::Send() in state 0
2018-05-04 09:28:10 248 1 Statut : Connexion à ... //Connecting to the FTP server
2018-05-04 09:28:10 248 1 Statut : Connexion établie, attente du message d'accueil... //Connection established, waiting for the welcome message
2018-05-04 09:28:11 248 1 Suivi : CFtpControlSocket::OnReceive()
2018-05-04 09:28:11 248 1 Réponse : 220 Service ready for new user.
2018-05-04 09:28:11 248 1 Suivi : CFtpLogonOpData::ParseResponse() in state 1
2018-05-04 09:28:11 248 1 Suivi : CControlSocket::SendNextCommand()
2018-05-04 09:28:11 248 1 Suivi : CFtpLogonOpData::Send() in state 2
2018-05-04 09:28:11 248 1 Commande : AUTH TLS
2018-05-04 09:28:11 248 1 Suivi : CFtpControlSocket::OnReceive()
2018-05-04 09:28:11 248 1 Réponse : 500 Syntax error, command unrecognized.
2018-05-04 09:28:11 248 1 Suivi : CFtpLogonOpData::ParseResponse() in state 2
2018-05-04 09:28:11 248 1 Suivi : CControlSocket::SendNextCommand()
2018-05-04 09:28:11 248 1 Suivi : CFtpLogonOpData::Send() in state 3
2018-05-04 09:28:11 248 1 Commande : AUTH SSL
2018-05-04 09:28:11 248 1 Suivi : CFtpControlSocket::OnReceive()
2018-05-04 09:28:11 248 1 Réponse : 500 Syntax error, command unrecognized.
2018-05-04 09:28:11 248 1 Suivi : CFtpLogonOpData::ParseResponse() in state 3
2018-05-04 09:28:11 248 1 Statut : Serveur non sécurisé, celui-ci ne supporte pas FTP sur TLS.// No TLS
2018-05-04 09:28:11 248 1 Suivi : CControlSocket::SendNextCommand()
2018-05-04 09:28:11 248 1 Suivi : CFtpLogonOpData::Send() in state 5
2018-05-04 09:28:11 248 1 Commande : USER user
2018-05-04 09:28:12 248 1 Suivi : CFtpControlSocket::OnReceive()
2018-05-04 09:28:12 248 1 Réponse : 331 User name okay, need password.
2018-05-04 09:28:12 248 1 Suivi : CFtpLogonOpData::ParseResponse() in state 5
2018-05-04 09:28:12 248 1 Suivi : CControlSocket::SendNextCommand()
2018-05-04 09:28:12 248 1 Suivi : CFtpLogonOpData::Send() in state 5
2018-05-04 09:28:12 248 1 Commande : PASS ****
2018-05-04 09:28:12 248 1 Suivi : CFtpControlSocket::OnReceive()
2018-05-04 09:28:12 248 1 Réponse : 230 User logged in, proceed.
2018-05-04 09:28:12 248 1 Suivi : CFtpLogonOpData::ParseResponse() in state 5
2018-05-04 09:28:12 248 1 Suivi : CControlSocket::SendNextCommand()
2018-05-04 09:28:12 248 1 Suivi : CFtpLogonOpData::Send() in state 6
2018-05-04 09:28:12 248 1 Commande : SYST
2018-05-04 09:28:12 248 1 Suivi : CFtpControlSocket::OnReceive()
2018-05-04 09:28:12 248 1 Réponse : 215 Windows_CE version 6.0.
2018-05-04 09:28:12 248 1 Suivi : CFtpLogonOpData::ParseResponse() in state 6
2018-05-04 09:28:12 248 1 Suivi : CControlSocket::SendNextCommand()
2018-05-04 09:28:12 248 1 Suivi : CFtpLogonOpData::Send() in state 7
2018-05-04 09:28:12 248 1 Commande : FEAT
2018-05-04 09:28:13 248 1 Suivi : CFtpControlSocket::OnReceive()
2018-05-04 09:28:13 248 1 Réponse : 211- Features supported
2018-05-04 09:28:13 248 1 Réponse : REST SIZE STREAM
2018-05-04 09:28:13 248 1 Réponse : 211 End
2018-05-04 09:28:13 248 1 Suivi : CFtpLogonOpData::ParseResponse() in state 7
2018-05-04 09:28:13 248 1 Statut : Le serveur ne supporte pas les caractères non-ASCII. //Doesn't support non ASCII characters
2018-05-04 09:28:13 248 1 Statut : Connecté // Connected
2018-05-04 09:28:13 248 1 Suivi : Measured latency of 296 ms
2018-05-04 09:28:13 248 1 Suivi : CFtpControlSocket::ResetOperation(0)
2018-05-04 09:28:13 248 1 Suivi : CControlSocket::ResetOperation(0)
2018-05-04 09:28:13 248 1 Statut : Récupération du contenu du dossier... //Getting directory content
2018-05-04 09:28:13 248 1 Suivi : CControlSocket::SendNextCommand()
2018-05-04 09:28:13 248 1 Suivi : CFtpListOpData::ListSend() in state 0
2018-05-04 09:28:13 248 1 Suivi : CFtpChangeDirOpData::Send() in state 0
2018-05-04 09:28:13 248 1 Suivi : CFtpChangeDirOpData::Send() in state 1
2018-05-04 09:28:13 248 1 Commande : PWD
2018-05-04 09:28:13 248 1 Suivi : CFtpControlSocket::OnReceive()
2018-05-04 09:28:13 248 1 Réponse : 257 "/".
2018-05-04 09:28:13 248 1 Suivi : CFtpChangeDirOpData::ParseResponse() in state 1
2018-05-04 09:28:13 248 1 Suivi : CFtpControlSocket::ResetOperation(0)
2018-05-04 09:28:13 248 1 Suivi : CControlSocket::ResetOperation(0)
2018-05-04 09:28:13 248 1 Suivi : CControlSocket::ParseSubcommandResult(0)
2018-05-04 09:28:13 248 1 Suivi : CFtpListOpData::SubcommandResult() in state 1
2018-05-04 09:28:13 248 1 Suivi : CControlSocket::SendNextCommand()
2018-05-04 09:28:13 248 1 Suivi : CFtpListOpData::ListSend() in state 2
2018-05-04 09:28:13 248 1 Suivi : CFtpRawTransferOpData::Send() in state 1
2018-05-04 09:28:13 248 1 Commande : TYPE I
2018-05-04 09:28:13 248 1 Suivi : CFtpControlSocket::OnReceive()
2018-05-04 09:28:13 248 1 Réponse : 200 Command okay.
2018-05-04 09:28:13 248 1 Suivi : CFtpRawTransferOpData::ParseResponse() in state 1
2018-05-04 09:28:13 248 1 Suivi : CControlSocket::SendNextCommand()
2018-05-04 09:28:13 248 1 Suivi : CFtpRawTransferOpData::Send() in state 2
2018-05-04 09:28:13 248 1 Commande : PASV
2018-05-04 09:28:13 248 1 Suivi : CFtpControlSocket::OnReceive()
2018-05-04 09:28:13 248 1 Réponse : 227 Entering Passive Mode (x,x,x,x,200,64).
2018-05-04 09:28:13 248 1 Suivi : CFtpRawTransferOpData::ParseResponse() in state 2
2018-05-04 09:28:13 248 1 Suivi : CControlSocket::SendNextCommand()
2018-05-04 09:28:13 248 1 Suivi : CFtpRawTransferOpData::Send() in state 4
2018-05-04 09:28:13 248 1 Suivi : Binding data connection source IP to control connection source IP (myIP)
2018-05-04 09:28:13 248 1 Commande : LIST
2018-05-04 09:28:14 248 1 Suivi : CTransferSocket::OnConnect
2018-05-04 09:28:14 248 1 Suivi : CFtpControlSocket::OnReceive()
2018-05-04 09:28:14 248 1 Réponse : 125 Data connection already open; transfer starting.
2018-05-04 09:28:14 248 1 Suivi : CFtpRawTransferOpData::ParseResponse() in state 4
2018-05-04 09:28:14 248 1 Suivi : CControlSocket::SendNextCommand()
2018-05-04 09:28:14 248 1 Suivi : CFtpRawTransferOpData::Send() in state 5
2018-05-04 09:28:14 248 1 Suivi : CFtpControlSocket::OnReceive()
2018-05-04 09:28:14 248 1 Réponse : 226 Closing data connection. 
2018-05-04 09:28:14 248 1 Suivi : CFtpRawTransferOpData::ParseResponse() in state 5
2018-05-04 09:28:14 248 1 Suivi : CControlSocket::SendNextCommand()
2018-05-04 09:28:14 248 1 Suivi : CFtpRawTransferOpData::Send() in state 8
2018-05-04 09:28:14 248 1 Suivi : CTransferSocket::OnClose(0)
2018-05-04 09:28:14 248 1 Suivi : CTransferSocket::TransferEnd(1)
2018-05-04 09:28:14 248 1 Suivi : CFtpControlSocket::TransferEnd()
2018-05-04 09:28:14 248 1 Suivi : CFtpControlSocket::ResetOperation(0)
2018-05-04 09:28:14 248 1 Suivi : CControlSocket::ResetOperation(0)
2018-05-04 09:28:14 248 1 Suivi : CControlSocket::ParseSubcommandResult(0)
2018-05-04 09:28:14 248 1 Suivi : CFtpListOpData::SubcommandResult() in state 3
2018-05-04 09:28:14 248 1 Suivi : CFtpControlSocket::ResetOperation(0)
2018-05-04 09:28:14 248 1 Suivi : CControlSocket::ResetOperation(0)
2018-05-04 09:28:14 248 1 Statut : Contenu du dossier "/" affiché avec succès // "/" directory successfully displayed

我继续搜索,发现了一些奇怪的东西.数据连接在FileZilla中立即关闭,但仍然可以获取文件列表,也许我应该使用PHP进行处理:

I continued searching and I found something weird. The data connection is closed instantly in FileZilla, but it can still get the list of files, maybe I should work on it with PHP :

Commande :  PASV
Réponse :   227 Entering Passive Mode (x,x,x,x,19,201)
Commande :  LIST
Réponse :   150 File status okay; about to open data connection.
Réponse :   226 Closing data connection. 
Statut :    Contenu du dossier affiché avec succès // The directory's content is well displayed

这就是它与另一台服务器一起工作的方式

And this is how it works with another server

Commande :  PASV
Réponse :   227 Entering Passive Mode (x,x,x,x,15,73)
Commande :  LIST
Réponse :   150 File status okay; about to open data connection.
Réponse :   226 Transfer complete
Statut :    Contenu du dossier affiché avec succès //Sucessfully displayed

推荐答案

检查您从服务器上获取文件的目录是否具有正确的权限,或者文件夹本身...假设您正在尝试获取PHP的服务器要使用的是Linux服务器,请记住您具有文件或文件夹所有者,特定用户和全局用户的权限,因此,当您更改权限时,将使用chmod 777 ...

Check if the directory you are getting files from on the server has the correct permissions, or the folder itself... Assuming the server you are trying to get PHP to work on is a linux server remember you have permissions for the owner of the file or folder, specific users and global users hence when you change permissions you would use chmod 777...

-要检查的另一件事是,当您使用php连接服务器时,您的守护程序/客户端将被标识为哪种用户,从而更容易知道您拥有什么权限.

-Another thing to check is whether when you use connect to the server using php what kind of user is your daemon/client identified as from there it would be easier to know what permissions you have.

-另外,我建议您检查服务器是否已配置为允许外部客户端/连接在文件上工作.您的服务器管理员可能已对服务器进行了不同的配置,具有FileZilla访问权限的是您使用其他端口的ftp帐户,本例中的端口为21,但是问题是您的PHP应用程序试图使用哪个端口.希望这可以指导您了解可能存在的问题.

-Also I would advise you check if the server has been configured to allow for external clients/connections to work on the files. Your Server Administrator might have configured the Server differently, having FileZilla access is your ftp account using a different port, which is port 21 in this instance but the question is which port is your PHP application trying to use. Hope this guides you as to get an idea as to what could be the problem.

这篇关于我无法在使用PHP的FTP服务器上工作,但连接正常,但无法获取文件或其他东西.它与FileZilla一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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