【问题标题】:ftp_connect() is not working when using cron使用 cron 时 ftp_connect() 不起作用
【发布时间】:2014-01-27 21:46:43
【问题描述】:

这是有问题的行,仅用于测试:

var_dump(ftp_connect("ftp.something.com"));

如果我从浏览器调用上面的脚本,它可以正常工作,响应如下:

resource(1) of type (FTP Buffer)

如果我尝试使用 cron 或从 shell 调用它,响应是:

bool(false)

看起来 ftp_connect 函数使用 cron 工作正常,但不知何故它无法连接到外部位置。如果我将 ftp 地址更改为“localhost”,它会再次正常工作:

resource(4) of type (FTP Buffer)

知道什么可能导致这个问题吗?可能是服务器上的防火墙?

【问题讨论】:

    标签: php shell ftp cron


    【解决方案1】:

    通过代理连接到 ftp 服务器

    $ftp_server = "proxy"; f.e. 123.456.789.10
    $ftp_user_name = "username@ftpserver"; f.e. exampleuk@www.example.uk
    $ftp_user_pass = "password";
    
    $conn_id = ftp_connect($ftp_server, 2121);
    $login_result = ftp_login( $conn_id, $ftp_user_name, $ftp_user_pass );
    

    另一个有用的函数是set_time_limit(0);

    【讨论】:

      猜你喜欢
      • 2020-09-21
      • 2015-02-23
      • 2014-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-29
      • 1970-01-01
      相关资源
      最近更新 更多