简体   繁体   中英

ftp_login authentication fails

I have something set up like this (only the names have changed):

$connection = ftp_connect('hostname.com') or die('Connection failure');
$login_result = ftp_login($connection, 'username', 'password');

This outputs the error:

ftp_login(): Authentication failed. in /path/to/file.php

Copy-pasting from my PHP into an FTP client like Cyberduck succeeds. The resource $connection seems to exist because otherwise it should die before the ftp_login line. I'm 100% sure that I have the correct username and password (as evidenced by the Cyberduck test).

The only thing that throws alarm bells in my head is that I know PHP handles strings differently when there's an @ symbol at the front, and my password may or may not have one or more symbols in it.


EDIT:

Since Cyberduck is on my work machine and PHP is running on AWS, I decided to run two tests to narrow down the possibilities. I set up an SSH tunnel:

ssh -L 11111:foo.com:21 adam@foo.com

And ran Cyberduck on adam@localhost:11111 , getting this error message in console:

channel 3: open failed: connect failed: Connection refused

Inconclusive results to me.

So I brought over the 2 lines of PHP script to my machine, and got Authentication failed again. So it looks like a PHP problem...

It turns out that the problem was the password. I don't know why it's an issue, but having an ampersand ( & ) as the first character of the password was throwing things off. Changing the password to something that didn't have a leading ampersand worked.

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