Why is ftp_login() authentication failing?

4.4k Views Asked by At

I am attempting to use ftp_login() but continue to get the error:

Warning: ftp_login(): Login authentication failed in /path/to/file.php

I am 100% positive that the username and password are correct. Login succeeds when using an FTP client like WinSCP or FileZilla. There are no symbols in either the password or username.

Here's the code:

$ftp_host = 'host.com'; 
$ftp_user_name =  '[email protected]'; 
$ftp_user_pass = 'password';

$connect = ftp_connect( $ftp_host ) or die( "Couldn't connect to server!!!" );
$login_result = ftp_login( $connect, $ftp_user_name, $ftp_user_pass );

I am using HostGator and I am trying to transfer files this domain to a sub-domain also with HostGator.

Please help. Thanks!

2

There are 2 best solutions below

0
On BEST ANSWER

Try dropping @host.com from your $ftp_user_name string.

Use this to see if your credentials are correct:

if (ftp_login($connect, $ftp_user_name, $ftp_user_pass)) {
    echo "Connected as $ftp_user_name@$ftp_host\n";
} else {
    echo "Couldn't connect as $ftp_user_name\n";
}

Note, this code will show errors.

0
On

Try changing your ftp password, click View FTP Details and change your password. You're better off with a proper ftp client than a web based file manager though and also they're notorious for corrupting files.