我正在尝试使用以下代码通过 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);
Run Code Online (Sandbox Code Playgroud)
但我不断收到此错误:
ftp_login(): 登录名或密码不正确!
不过,我可以通过 FileZilla 等 FTP 程序成功使用这些凭据。我的凭据真的有错吗?
有任何想法吗?
FileZilla 日志文件:
$ftp_conn = ftp_connect('XXX.XX.XXX.XXX') or die("Could not connect");
$login = ftp_login($ftp_conn, 'USER', 'PASS');
var_dump($login);
Run Code Online (Sandbox Code Playgroud)
禁用加密的 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
Run Code Online (Sandbox Code Playgroud)
正如您的 FileZilla 日志所示,您的 FTP 服务器不允许未加密的连接。
Response: 331 This server does not allow plain FTP. You have to use FTP over TLS.
Run Code Online (Sandbox Code Playgroud)
PASS不幸的是,PHP 隐藏了该错误消息并仅传播对命令不相关的响应。
你必须使用ftp_ssl_connect而不是普通的ftp_connect:
$ftp_conn = ftp_ssl_connect('XXX.XX.XXX.XXX') or die("Could not connect");
Run Code Online (Sandbox Code Playgroud)