我有一个带有登录详细信息和来自 PHP 的安全 FTP 服务器,我正在尝试使用ftp_ssl_connect/ftp_connect
和ftp_login
函数连接到该安全 FTP 服务器,并将所有参数正确传递给函数,但我很惊讶它没有连接。
如果我尝试使用 ssh 从命令行连接到该安全 FTP 服务器,我可以这样做,但是当我尝试通过 php 代码连接时,它无法连接,所以我不确定为什么会这样?
还有其他使用 PHP 连接到 Secure FTP Server 的方法是什么?
编辑:我尝试使用ssh2_sftp
但仍然无法连接到安全的 FTP 服务器。
编辑 2:是否有任何其他方法可以使用 PHP 进行 SFTP,请告知。
更新:添加了使用 ssh2_sftp 连接到安全 FTP 服务器的代码,但它没有工作并且程序因消息而终止Cannot connect to Server
<?php
$connection = ssh2_connect('www.server.com', 22);
ssh2_auth_password($connection, 'username', 'password');
$sftp = ssh2_sftp($connection) or die ("Cannot connect to server");
$stream = fopen("ssh2.sftp://$sftp/path/to/file", 'r');
?>