【发布时间】:2021-09-08 04:57:51
【问题描述】:
我编写了这段代码,用于使用 PHP 连接到 FTP 服务器。连接正常,身份验证正常,但是当我使用 php_nlist 或 php_rawlist 时,脚本会无限期加载。
对于被动模式,我使用了命令 ftp_pasv($conn_id, true) 和 ftp_raw($conn_id, 'PASV'),但脚本不起作用。
$ftp_server = 'xxx';
$ftp_user_name = 'xxx';
$ftp_user_pass = 'xxx';
$conn_id = ftp_ssl_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);
if ($login_result)
{
echo("Successful authentication<br><br>");
}
else
{
echo("authentication error<br><br>");
}
ftp_pasv($conn_id, true) or die("Passive mode failed");
$list = ftp_nlist($conn_id, "/");
foreach ($list as $file)
{
echo ($file."<br>");
}
我收到的错误是:
警告:ftp_nlist(): php_connect_nonb() 失败:操作正在进行中 (115)
但我可以使用我的 FTP 客户端登录:
2021-06-29 19:07:47 753 1 Status: Connecting to 151.41.239.70:21...
2021-06-29 19:07:47 753 1 Status: Connection established, waiting for welcome message...
2021-06-29 19:07:47 753 1 Response: 220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
2021-06-29 19:07:47 753 1 Response: 220-You are user number 1 of 10 allowed.
2021-06-29 19:07:47 753 1 Response: 220-Local time is now 19:07. Server port: 21.
2021-06-29 19:07:47 753 1 Response: 220 You will be disconnected after 10 minutes of inactivity.
2021-06-29 19:07:47 753 1 Command: AUTH TLS
2021-06-29 19:07:47 753 1 Response: 234 AUTH TLS OK.
2021-06-29 19:07:47 753 1 Status: Initializing TLS...
2021-06-29 19:07:47 753 1 Status: Verifying certificate...
2021-06-29 19:07:47 753 1 Status: TLS connection established.
2021-06-29 19:07:47 753 1 Command: USER nertobacos
2021-06-29 19:07:47 753 1 Response: 331 User nertobacos OK. Password required
2021-06-29 19:07:47 753 1 Command: PASS ********
2021-06-29 19:07:47 753 1 Response: 230 OK. Current restricted directory is /
2021-06-29 19:07:47 753 1 Status: Server does not support non-ASCII characters.
2021-06-29 19:07:47 753 1 Command: PBSZ 0
2021-06-29 19:07:47 753 1 Response: 200 PBSZ=0
2021-06-29 19:07:47 753 1 Command: PROT P
2021-06-29 19:07:47 753 1 Response: 200 Data protection level set to "private"
2021-06-29 19:07:47 753 1 Status: Logged in
2021-06-29 19:07:47 753 1 Status: Retrieving directory listing...
2021-06-29 19:07:47 753 1 Command: PWD
2021-06-29 19:07:47 753 1 Response: 257 "/" is your current location
2021-06-29 19:07:47 753 1 Command: TYPE I
2021-06-29 19:07:47 753 1 Response: 200 TYPE is now 8-bit binary
2021-06-29 19:07:47 753 1 Command: PORT 192,168,1,108,195,143
2021-06-29 19:07:47 753 1 Response: 200 PORT command successful
2021-06-29 19:07:47 753 1 Command: MLSD
2021-06-29 19:07:47 753 1 Response: 150 Connecting to port 50063
2021-06-29 19:07:47 753 1 Response: 226-Options: -a -l
2021-06-29 19:07:47 753 1 Response: 226 4 matches total
2021-06-29 19:07:47 753 1 Status: Directory listing of "/" successful
【问题讨论】: