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

时间:2018-05-23 03:02:56

标签: php ftp

我正在尝试使用以下代码通过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

1 个答案:

答案 0 :(得分: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");
相关问题