Why would ftp_connect() return false on production server if it works elsewhere for connecting to the same FTP server?

泪湿孤枕 提交于 2021-01-29 04:35:51

问题


I have a script that uses ftp_connect() among other FTP PHP functions for uploading a file.

ftp_connect() works when executed on my local development server for connecting to a remote FTP server. The same script, when executed on the remote server does not work for connecting to the exact same FTP server.

Could somebody please point me in the right direction?

Thanks!

Here is the code:

error_reporting(E_ERROR | E_WARNING | E_PARSE);
$server = 'ftp.someserver.com';
$ftpConn = ftp_connect($server);
if(!$ftpConn)
    echo 'failed';
else
    echo 'success';

No errors are reported.


回答1:


So if I understand it correctly then the script above is installed on the server that you're trying to access using FTP (ie. the script is opening a local FTP connection)? What's the use? FTP in PHP is only useful to transfer files between 2 servers, you cannot use it to transfer files from the client to the server (since the script is executed on the server).

edit

Something I didn't add in my original comment : you could use a Java FTP applet if you want to transfer files from the client to the server. But be aware of the security issues involved (because the user credentials can be sniffed :p).




回答2:


Probably firewall issues. On top of that, FTP was not designed with NAT in mind.

Try to login to the production server and use a ftp client to do the same connection.




回答3:


I do not know the things inside it very well but I want to give my little help.My server is ubuntu Linux with Apache、PHP and MySQL,and my develop env is MAMP on Mac.

  1. I met the problem suddenly and cannot find what happened because it was worked yesterday,I searched many answers and can't solved it.The ftp_connect($ftp_server) only return bool(false),but I can use my FileZilla,interesting,is it?

  2. So I try to connect the server from my command line,like ftp 111.22.333.44,It shows:

    500 OOPS: cannot read user list file:/etc/vsftpd/vsftpd.user_list

  3. I login in my ubuntu server, and didn't find the vsftpd directory,and the vsftpd.user_listis in the directory /etc/,still don't know what happened.

  4. So I simply create the directory and copy the file vsftpd.user_list to it.Then I try ftp 111.22.333.44(your IP address) again and it works now.

hope it help someone else.



来源:https://stackoverflow.com/questions/2987746/why-would-ftp-connect-return-false-on-production-server-if-it-works-elsewhere

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