Posted on

ftp_connect function not working to connect with localhost in MAC

I have tried so many things but ftp_connect and ftp_ssl_connect are not working in my development instance.

I am using MAC and PHP8.1, I am trying to connect to localhost with the below simple script:

<?php

// Connect to FTP server
$ftp_server = “localhost”;

// Establish ftp connection
$ftp_connection = ftp_connect($ftp_server, 22, 10)
or die(“Could not connect to $ftp_server”);

if($ftp_connection) {
echo “Successfully connected to the ftp server!”;

// Closing connection
ftp_close($ftp_connection);
}

?>

This is always returning bool(false) instead of the FTP/Connection object. I have also checked the Firewall, it is disabled on my local machine.

Do we need to configure anything in order to work with it?

Thanks

Leave a Reply

Your email address will not be published.