【发布时间】:2020-05-11 15:00:25
【问题描述】:
我的 ftp_nlist 函数有问题,即当我在生产服务器上运行代码时它返回 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 函数之后也不起作用。
知道这可能是什么问题吗?
提前致谢。
【问题讨论】:
标签: php