使用PHP测试FTP连接 [英] Test FTP connection with PHP

查看:109
本文介绍了使用PHP测试FTP连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用下面的PHP脚本来测试FTP连接。目前它正在打印一组文件,如果它成功连接的话。

如果它能够连接,我怎样才能让它显示信息?像'连接成功'。

  $ con = ftp_connect($ server)或die(Could not connect); 
ftp_login($ con,$ username,$ password);
print_r(ftp_nlist($ con,。));
ftp_close($ con);

编辑

<现在我已经开始工作了,但是,我已经在MediaTemple服务器上的几个域中测试过了,他们都似乎超时了。然而,它适用于我尝试过的所有其他域。他们的服务器是否阻止了请求?

解决方案

只要检查 ftp_nlist()
$ p
$ b $ echo is_array(ftp_nlist( $ con,。))? '连接!':'不连接! :


I am using the PHP script below to test FTP connections. Currently it is printing an array of the files, if it successfully connects.

How can I get it to also display a message, if it is able to connect? Like 'Connection Successful'.

$con = ftp_connect($server) or die("Couldn't connect"); 
ftp_login($con,  $username,  $password);
print_r(ftp_nlist($con, "."));
ftp_close($con);

EDIT

I have it working now but, I've tested this on a few domains I have on a MediaTemple server and they all seem be timing out. Yet, it works with all other domains I have tried. Are their servers blocking the request?

解决方案

Simply do a check if ftp_nlist() is an array.

Like:

echo is_array(ftp_nlist($con, ".")) ? 'Connected!' : 'not Connected! :(';

References:

这篇关于使用PHP测试FTP连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆