简体   繁体   English

ftp_login身份验证失败

[英]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. 从我的PHP复制粘贴到Cyber​​yuck等FTP客户端成功。 The resource $connection seems to exist because otherwise it should die before the ftp_login line. 资源$connection似乎存在,因为否则它应该在ftp_login行之前ftp_login I'm 100% sure that I have the correct username and password (as evidenced by the Cyberduck test). 我100%确保我具有正确的用户名和密码(如Cyber​​duck测试所证明的)。

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. 唯一让我警惕的是,我知道PHP的前面有一个@符号时,对字符串的处理方式有所不同,并且我的密码中可能有也可能没有一个或多个符号。


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. 由于Cyber​​duck在我的工作计算机上并且PHP在AWS上运行,因此我决定运行两个测试以缩小可能性。 I set up an SSH tunnel: 我设置了SSH隧道:

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

And ran Cyberduck on adam@localhost:11111 , getting this error message in console: 然后在adam@localhost:11111上运行Cyber​​duck,在控制台中得到以下错误消息:

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. 因此,我将两行PHP脚本带到了我的机器上,并再次使Authentication failed So it looks like a PHP problem... 所以它看起来像一个PHP问题...

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. 将密码更改为没有前导号的字符可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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