Php operation ftp error

Hello, everyone. I have a server, (linux), which was going to test the php operation ftp, but has been unable to connect, as follows:

<?
error_reporting(E_ALL);

    $host = "XXX";
    $user = "XXX";
    $pwd = "XXX";
    $port = 2121;
    $f_conn = ftp_connect($host,2121);
    var_dump($f_conn);

return error: bool (false)

ftp_connect cannot establish a connection. I tested that other servers can connect.
it is possible to connect directly with ftp software (connection protocol: ftp), what is the situation?
php version configuration problem or firewall? Or whatever.

phpinfo:

clipboard.png

clipboard.png

clipboard.png

ftp:

Mar.22,2021

you can check whether FTP is supported via phpinfo, FTP support to see if this is enabled, if it is not enabled


  1. use ftp software to connect directly to see if ftp protocol or sftp protocol is used. If the connection is successful using sftp protocol, you cannot use the ftp_connect function.
  2. check whether the ftp extension is installed in phpinfo
  3. to use ftp, you must first build a ftp service on the server and use the tp_connect function to check whether the parameters are correct
  4. here is a test code for you
<?php
// 
$conn_id = ftp_connect('116.196.116.31');
var_dump($conn_id);

?>
Menu