ftp_connect() does not return a resource id

旧街凉风 提交于 2021-02-08 10:38:24

问题


Suddenly when I'm doing this on my server:

<?php 
$connection = ftp_connect("ftpserver"); // connect to server
print($connection);print("test");die();
?>

It does not return a Resource id #.

It happens only on a particular server, if I try the same code on another server it will return:

Resource id #2test

Is it a server configuration? Nothing changed on that server recently. It prints just "test", no null or something else. I've tried multiple ftp servers to make sure that the server IP is not banned.

Tried function_exists('ftp_connect') and it is.

Update: check /var/log/syslog to see if it is blocked by firewall.


回答1:


The ftp_connect function returns false, if the connection fails.

Printing false yields nothing (the false converts to an empty string).

Use the var_dump($connection) to verify.

You will most likely get:

bool(false)

Meaning that you cannot connect to the "ftpserver".

The ftp_connect should issue a warning with details about the connection problem.



来源:https://stackoverflow.com/questions/36574741/ftp-connect-does-not-return-a-resource-id

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!