php可以忽略ftp数据通道的建议ip并直接转到服务器吗


Can php ignore the suggested ip for the ftp data channel and go direct to server?

我已经成功地从客户端下载了一个远程文件一段时间了,由于某种原因,他们的服务器现在返回了一个私有ip。FileZilla足够聪明,可以使用服务器地址。

Status: Server sent passive reply with unroutable address. Using server address instead.

我看不出有什么方法可以使用php内置的ftp代码来实现这一点。

    $conn_id = ftp_connect($ftp_server);
    $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); 
    ftp_pasv($conn_id, TRUE);
    if (ftp_get($conn_id, $downloaded_file, $server_file, FTP_BINARY)) {
        printf("Successfully downloaded %s'n", $downloaded_file);
    } else {
        printf("There was a problem downloading %s'n %s'n", 
              $server_file, 
              print_r(error_get_last(), TRUE)
        );
        exit(1);
    }
    ftp_close($conn_id);

有没有办法让php忽略数据通道的建议ip并使用服务器的ip

这是可能的,从5.6.8/7.0.2开始,使用以下选项:

ftp_set_option($conn_id, FTP_USEPASVADDRESS, false);

相关提交