首页 > 解决方案 > PHP ftp_login 警告“您将在 10 分钟不活动后断开连接”

问题描述

我写了这个脚本来连接一个 FTP 服务器

$ftp_server = 'ftp.xxx.com';
$ftp_user_name = 'myusername';
$ftp_user_pass = 'mypassword';

$conn_id = ftp_connect($ftp_server,21);
if ($conn_id)
{
    echo("Connected to FTP<br><br>");
}
else
{
    echo("Connection error<br>");
}
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
var_dump($login_result);

我正确地看到“已连接到服务器 FTP”,但出现此错误后

警告:ftp_login():您将在 10 分钟不活动后断开连接。

我没有激活防火墙。

我可以使用 FileZilla 登录:

2021-06-24 11:58:24 72106 1 Status: Resolving address of ftp.cuimhni.it
2021-06-24 11:58:24 72106 1 Status: Connecting to 62.149.141.10:21...
2021-06-24 11:58:24 72106 1 Status: Connection established, waiting for welcome message...
2021-06-24 11:58:24 72106 1 Response: 220-#
2021-06-24 11:58:24 72106 1 Response: 220-#                                 
2021-06-24 11:58:24 72106 1 Response: 220-#  Aruba.it                    
2021-06-24 11:58:24 72106 1 Response: 220-#  The Web Hosting Company     
2021-06-24 11:58:24 72106 1 Response: 220-#                                 
2021-06-24 11:58:24 72106 1 Response: 220-#
2021-06-24 11:58:24 72106 1 Response: 220 This is a private system - No anonymous login
2021-06-24 11:58:24 72106 1 Command: AUTH TLS
2021-06-24 11:58:24 72106 1 Response: 234 AUTH TLS OK.
2021-06-24 11:58:24 72106 1 Status: Initializing TLS...
2021-06-24 11:58:24 72106 1 Status: Verifying certificate...
2021-06-24 11:58:26 72106 1 Status: TLS connection established.
2021-06-24 11:58:26 72106 1 Command: USER 1515289@aruba.it
2021-06-24 11:58:26 72106 1 Response: 331 User 1515289@aruba.it OK. Password required
2021-06-24 11:58:26 72106 1 Command: PASS **************
2021-06-24 11:58:26 72106 1 Response: 230-Your bandwidth usage is restricted
2021-06-24 11:58:26 72106 1 Response: 230 OK. Current restricted directory is /
2021-06-24 11:58:26 72106 1 Command: SYST
2021-06-24 11:58:26 72106 1 Response: 215 UNIX Type: L8
2021-06-24 11:58:26 72106 1 Command: FEAT
2021-06-24 11:58:26 72106 1 Response: 211-Extensions supported:
2021-06-24 11:58:26 72106 1 Response:  UTF8
2021-06-24 11:58:26 72106 1 Response:  EPRT
2021-06-24 11:58:26 72106 1 Response:  IDLE
2021-06-24 11:58:26 72106 1 Response:  MDTM
2021-06-24 11:58:26 72106 1 Response:  SIZE
2021-06-24 11:58:26 72106 1 Response:  MFMT
2021-06-24 11:58:26 72106 1 Response:  REST STREAM
2021-06-24 11:58:26 72106 1 Response:  MLST type*;size*;sizd*;modify*;UNIX.mode*;UNIX.uid*;UNIX.gid*;unique*;
2021-06-24 11:58:26 72106 1 Response:  MLSD
2021-06-24 11:58:26 72106 1 Response:  PRET
2021-06-24 11:58:26 72106 1 Response:  AUTH TLS
2021-06-24 11:58:26 72106 1 Response:  PBSZ
2021-06-24 11:58:26 72106 1 Response:  PROT
2021-06-24 11:58:26 72106 1 Response:  ESTA
2021-06-24 11:58:26 72106 1 Response:  PASV
2021-06-24 11:58:26 72106 1 Response:  EPSV
2021-06-24 11:58:26 72106 1 Response:  SPSV
2021-06-24 11:58:26 72106 1 Response:  ESTP
2021-06-24 11:58:26 72106 1 Response: 211 End.
2021-06-24 11:58:26 72106 1 Command: OPTS UTF8 ON
2021-06-24 11:58:26 72106 1 Response: 504 Unknown command
2021-06-24 11:58:26 72106 1 Command: PBSZ 0
2021-06-24 11:58:26 72106 1 Response: 200 PBSZ=0
2021-06-24 11:58:26 72106 1 Command: PROT P
2021-06-24 11:58:26 72106 1 Response: 200 Data protection level set to "private"
2021-06-24 11:58:26 72106 1 Status: Logged in

标签: phpauthenticationftp

解决方案


当您使用 FileZilla 登录时,它使用加密的 FTPS 连接。

要在 PHP 中做同样的事情,请使用ftp_ssl_connect, 而不是ftp_connect.


推荐阅读