0

尝试使用以下代码连接到远程 sftp:

    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);

我得到的结果是“连接失败”

远程 sftp 服务器需要基于 TLS 的显式 FTP(这是我使用 filezilla 进行连接的方式 - 并且连接正常)

如何使用 ssh2_connect 在 TLS 上定义显式 FTP?

编辑 也尝试与 ftp_ssl_connect 连接

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

这里的结果相同:“连接失败”

4

1 回答 1

0

ssh2_connect(和其他ssh2_*功能)用于 SSH 和 SFTP。

基于 TLS 的显式 FTP 是一个完全不同的协议。用于该用途ftp_ssl_connect和其他ftp_*功能。

于 2019-11-27T07:48:13.557 回答