0

Trying to connect to remote sftp using the following code:

    if( ! function_exists('ssh2_connect') ){
        die( 'Missing ssh2_connect' );
    }

    $callbacks = array(
        'disconnect' => function( $reason, $message, $language ){

            printf("Server disconnected with reason code [%d] and message: %s\n",
           $reason, $message);

        },
        'debug' => array( $this , function( $message, $language, $always_display ){

            printf("%s %s %s\n",$message,$language,$always_display);

        }, )
    );

    $connection = ssh2_connect( $this->ftp_ip , $this->ftp_port , array() , $callbacks ) or die("Connection failed:");

    ssh2_auth_password($connection, $this->ftp_user , $this->ftp_pass );

    $sftp = ssh2_sftp($connection);

THe result that i get is "Connection failed"

The remote sftp server requires Explicit FTP over TLS (this is how I use filezilla to connect - and the connection is working)

How can i define Explicit FTP over TLS using ssh2_connect ?

EDIT Tried also connecting with ftp_ssl_connect

$connection = ftp_ssl_connect( $this->ftp_ip , $this->ftp_port ) or die("Connection failed:");

Same result here: "Connection failed"

lior r
  • 2,220
  • 7
  • 43
  • 80

1 Answers1

0

ssh2_connect (and other ssh2_* functions) is for SSH and SFTP.

Explicit FTP over TLS is a completely different protocol. For that use ftp_ssl_connect and other ftp_* functions.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • Forgot to mention that i have tried it as well $connection = ftp_ssl_connect( $this->ftp_ip , $this->ftp_port ) or die("Connection failed:"); - it returned connection failed – lior r Nov 27 '19 at 07:56
  • What is the value of `ftp_ip` and `ftp_port`? Can you also post a FileZilla log file? Are you running FileZilla on the same machine as your PHP code? – Martin Prikryl Nov 27 '19 at 07:59