简体   繁体   English

PHP ftp_connect()始终返回false,但首先使用的ftp服务器除外。

[英]PHP ftp_connect() returns false always except with first used ftp server..!

The problem is .. 问题是 ..
I just used ftp_connect() for the first time on my server 我第一次在服务器上使用ftp_connect()

<?php
$ftp_connect = ftp_connect('ftp.server.com') or die('<b>FTP Connection Error ...</b>');
$login_result = ftp_login($ftp_connect, 'ftp_username','ftp_password') or die('<b>FTP Login Error ...Check Your UserName and Password</b>');
ftp_pasv($ftp_connect,true);    
?>

It worked fine and returned true.Every thing works fine with that ftp server (ftp.server.com) 它工作正常并返回true。该ftp服务器(ftp.server.com)一切正常

Then next time I used the same server and everything was fine...BUT when I tried with another server (say: ftp.server2.com) it returned false,ie host not found ..!! 然后,下次我使用同一台服务器,并且一切都很好...但是,当我尝试另一台服务器(例如:ftp.server2.com)时,它返回false,即找不到主机..! I tried with all my friends ftp servers and nothing could connect except that one(ftp.server.com) what's actually going on ... why is this happening and how can I solve this ... right now i can't connect any ftp server (except my ftp.server.com) .... Thanx in advance ... 我与所有朋友的ftp服务器进行了尝试,但除了一个(ftp.server.com)实际发生的事情之外,其他任何设备都无法连接...为什么发生这种情况以及如何解决这个问题...现在我无法连接任何服务器ftp服务器(我的ftp.server.com除外)....预先感谢...

And The above thing works fine on my pc (IIS,PHP 5.3.8) 上面的东西在我的电脑上正常工作(IIS,PHP 5.3.8)

Updated : ahhh ....... figured out the problem .... but didn't find a solution.!!!! 更新:啊........解决了问题..但是没有找到解决方法。!!!! the server (here: ftp.server.com) has the same IP which the host server, where the above php is hosted - has.... and soo the ftp_connect() worked on it.... reason is both the servers ftp and http host are from same web hosting provider... 该服务器(此处为ftp.server.com)具有与托管上述php的主机服务器相同的IP-....并且ftp_connect()也可以在其上工作。...原因是两个服务器ftp和http主机来自同一网站托管提供商...

Now its clear, (I think) that firewall is the main reason for all the problem .... how to fix that firewall...?? 现在很明显,(我认为)防火墙是所有问题的主要原因..如何修复该防火墙...? plz help.... Thanx again.. 请帮助...。再次感谢

You are not specifying a port number. 您未指定端口号。 PHP's ftp_connect() will use 21 as the default port number if you don't specify one. 如果未指定,则PHP的ftp_connect()将使用21作为默认端口号。 This script may have worked for the first server because it was running on port 21, but the other servers may be failing because they're running on different ports. 该脚本可能对第一台服务器有效,因为它在端口21上运行,但是其他服务器可能由于在不同端口上运行而失败。 Ask your friend(s) what port they're using, or use something like nmap to find it yourself. 询问您的朋友他们正在使用哪个端口,或者使用nmap之类的东西自己找到它。

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

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