繁体   English   中英

php ftp_nlist function 返回 504 网关超时错误

[英]php ftp_nlist function returns 504 Gateway Timeout error

我对 ftp_nlist function 有问题,即当我在生产服务器上运行代码时它返回 504 网关超时错误,在 localhost 上工作正常。

我的代码是:

   $connection_id = ftp_connect( $host, $port, $timeout );

  if ( $connection_id === false ) {
    throw new \Exception( 'Unable to connect to FTP Server. Check the connection details and try again.' );
  }

  $login = @ftp_login($connection_id,  $username,  $password);

  if ( $login !== true ) {
    $error = 'Unable to log in. Check your username or password and try again.';
    throw new \Exception( $error );
  }

  $check_dir = @ftp_chdir( $connection_id, $ftp_folder );

  if ( !$check_dir ) {
    $error = 'Couldn\'t find directory '. esc_attr( $ftp_folder ).' on '. esc_attr( $host );
    throw new \Exception( $error );
  }

  $check_file = @ftp_nlist( $connection_id, $ftp_folder ) ?: array();

  // This is where error occurs

我尝试设置以下内容:

 ftp_set_option($connection_id, FTP_USEPASVADDRESS, false); // set ftp option
  ftp_pasv($connection_id, true); //make connection to passive mode

在 ftp_login function 之后,也不起作用。

知道这里可能是什么问题吗?

提前致谢。

如果您正在登录和更改目录,我假设最初连接到服务器不是问题。

删除ftp_nlist()前面的@可能会为您提供有关错误情况性质的更多信息。

顺便说一句,我唯一的想法是目录列表太长了,以至于您的连接在服务器返回之前就超时了。 您的脚本需要多长时间才能达到此错误?

如果您使用ftp_rawlist()ftp_mlsd() ,您会得到相同的行为吗?

不知道问题现在是否已解决,但我遇到了同样的问题。 我认为这是一个防火墙问题,大部分时间都被激活。 要修复它,我只需要添加这一行:

ftp_pasv($ftp_conn,true);

希望对某人有所帮助!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM