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:

    // 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

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?


  • "localhost" should be the server itself. Is there an FTP server running on that server? Can you anonymously FTP into that server? From your command line try ftp localhost (you may need to use the webserver user since the PHP script is running as that user)... You may need to use ftp_login Jun 23, 2022 at 14:45
  • Thanks, @MagePalExtensions for your reply. I tried ftp localhost, it is working and also I am able to connect through FTP client FileZilla. Please help me I am still unable to connect via ftp_connect.
    – Abhinav
    Jun 27, 2022 at 5:56
  • Take a look at stackoverflow.com/questions/280014/… Jun 28, 2022 at 12:03


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.