问题
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.
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 returnbool(false)
,but I can use my FileZilla,interesting,is it?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
I login in my ubuntu server, and didn't find the
vsftpd
directory,and thevsftpd.user_list
is in the directory/etc/
,still don't know what happened.So I simply create the directory and copy the file
vsftpd.user_list
to it.Then I tryftp 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