Connecting with ftp_connect but can not login PHP

1.4k views Asked by At

I am creating an application which connects to FTP(with secured connection). This Might be stupid question but I really need help. My query is-

I am creating application to connect to FTP server which is secured(FTP-SSL / FTP Secure). I have used two approaches

  1. ftp_connect()
  2. ftp_ssl_connect()

Approach 1 - ftp_connect()

<?php
        $ftp_server = "ftp.xxx.xxx";
        $ftp_user_name = "xxx";
        $ftp_user_pass = "xxxxxx";

        $conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");
        ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
?>

My problem is, connection is established but when I try to login it is throwing this error. When I remove ftp_login() I am not getting any error. I know this is because of ftps. That is why I used second approach.

Warning: ftp_login(): Sorry, cleartext sessions are not accepted on this server.

Approach 2 - ftp_ssl_connect()

<?php
        $ftp_host = 'ftp.xxx.xxx';
        $ftp_user = 'xxxxxx';
        $ftp_password = 'xxxxxx';

        var_dump(function_exists('ftp_ssl_connect'));

        if(function_exists('ftp_ssl_connect'))
        {
            $ftp_connection = @ftp_ssl_connect($this->ftp_host);
        }

        if($ftp_connection)
        {
            ftp_login($ftp_connection, $this->ftp_user, $this->ftp_password);
        }
    ?> 

I used this approach ftp_ssl_connect() to connect ftp (with secured connection server). But the statement is printing bool(False). This means ftp_ssl_connect() is not available to use.

What should I do to connect ftp (with secured connection) server?. I tried replacing ftps over ftp in URL. it is showing the same error.

Update - 1 application will be hosted at Linux server. I am developing and testing application on windows 7 machine.

0

There are 0 answers