即使使用正确的凭据,PHP ftp_login也会失败

问题描述 投票:1回答:1

我正在尝试使用以下代码通过PHP进行FTP登录:

$ftp_conn = ftp_connect('XXX.XX.XXX.XXX') or die("Could not connect");
$login = ftp_login($ftp_conn, 'USER', 'PASS');
var_dump($login);

但我一直收到这个错误:

ftp_login():登录或密码不正确!

但是,我可以使用FTP程序(如FileZilla)成功使用这些凭据。我的凭据真的错了吗?

有任何想法吗?

FileZilla日志文件:

Status: Disconnected from server
Status: Connecting to XXX.XX.XXX.XXX:21...
Status: Connection established, waiting for welcome message...
Response:   220 Welcome to Claytons FTPS
Command:    AUTH TLS
Response:   234 Using authentication type TLS
Status: Initializing TLS...
Status: Verifying certificate...
Status: TLS connection established.
Command:    USER alfresco
Response:   331 Password required for alfresco
Command:    PASS **********
Response:   230 Logged on

禁用加密的FileZilla日志文件:

Status: Disconnected from server
Status: Connecting to XXX.XX.XXX.XXX:21...
Status: Connection established, waiting for welcome message...
Response:   220 Welcome to Claytons FTPS
Command:    USER alfresco
Response:   331 This server does not allow plain FTP. You have to use FTP over TLS.
Command:    PASS **********
Response:   530 Login or password incorrect!
Error:  Critical error: Could not connect to server
php ftp
1个回答
2
投票

正如您的FileZilla日志所示,您的FTP服务器不允许未加密的连接。

Response:   331 This server does not allow plain FTP. You have to use FTP over TLS.

不幸的是,PHP隐藏了该错误消息并仅传播对PASS命令的无关响应。


你必须使用ftp_ssl_connect而不是普通的ftp_connect

$ftp_conn = ftp_ssl_connect('XXX.XX.XXX.XXX') or die("Could not connect");
© www.soinside.com 2019 - 2024. All rights reserved.