ftp_get 在实时服务器上失败(returns 错误)但在本地工作

ftp_get fails (returns false) on live server but works locally

我正在尝试使用此脚本从 FTP 源下载一个 zip 文件(在本地主机上它可以工作,但不能在 OVH 的实时服务器上工作)。

当 运行 它在实时服务器上时,我立即得到:

所有连接都很好,但在下载文件时卡住了。

可能是什么问题,或者我怎样才能得到一些错误报告?

有人认为我检查过:

还能是什么?

谢谢


// Connect to FTP server

// Use a correct ftp server
$ftp_server = "localhost";

// Use correct ftp username
$ftp_username="user";

// Use correct ftp password corresponding
// to the ftp username
$ftp_userpass="user";
    
// Establishing ftp connection
$ftp_connection = ftp_connect($ftp_server, 21)
    or die("Could not connect to $ftp_server");

if( $ftp_connection ) {
    echo "successfully connected to the ftp server!";
    
    // Logging in to established connection
    // with ftp username password
    $login = ftp_login($ftp_connection,
            $ftp_username, $ftp_userpass);
    
    if($login) {
        
        // Checking whether logged in successfully
        // or not
        echo "<br>logged in successfully!";
        
        // Name or path of the localfile to
        // where the file to be downloaded
        $local_file = "file.zip";
        
        // Name or path of the server file to
        // be downoaded
        $server_file = "file.zip";
        
        // Downloading the specified server file
        if (ftp_get($ftp_connection, $local_file,
                $server_file, FTP_BINARY)) {
            echo "<br>Successfully downloaded from"
                . " $server_file to $local_file.";
        }
        else {
            echo "<br>Error while downloading from"
                . " $server_file to $local_file.";
        }
            
    }
    else {
        echo "<br>login failed!";
    }
    
    // echo ftp_get_option($ftp_connection, 1);
    // Closeing connection
    
    if(ftp_close($ftp_connection)) {
        echo "<br>Connection closed Successfully!";
    }
}
?>

ftp_get 问题的最典型原因是 PHP 默认为 FTP 活动模式。在 99% 的情况下,必须切换到 FTP 被动模式,才能使传输正常进行。在 ftp_login:

之后使用 ftp_pasv function
ftp_pasv($connect, true) or die("Passive mode failed");