简体   繁体   中英

PHP ftp_login fails even with correct credentials

I'm attempting an FTP login via PHP with this code:

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

But I keep getting this error:

ftp_login(): Login or password incorrect!

However, I can successfully use these credentials with an FTP program such as FileZilla. Are my credentials actually wrong?

Any ideas?

FileZilla log file:

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 log file with disabled encryption:

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

As your FileZilla logs show, your FTP server does not allow unencrypted connection.

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

Unfortunately PHP hides away that error message and propagates only an irrelevant response to PASS command.


You have to use ftp_ssl_connect instead of plain ftp_connect :

$ftp_conn = ftp_ssl_connect('XXX.XX.XXX.XXX') or die("Could not connect");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM