Home  >  Article  >  Backend Development  >  获取服务器文件时间数据失败,强制+1后,仍然无法下载,请指点

获取服务器文件时间数据失败,强制+1后,仍然无法下载,请指点

WBOY
WBOYOriginal
2016-06-23 13:56:291163browse

$host = 'ftp.mozilla.org';        $user = '';        $password = '';        $remotefile = '/pub/mozilla.org/firefox/releases/30.0b7/linux-x86_64/en-US/firefox-30.0b7.tar.bz2';        $localfile = '/home/username/firefox-29.0.1.tar.bz2'; $conn = ftp_connect($host);  $remotetime = ftp_mdtm($conn, $localfile);            if(!($remotetime) >= 0){                echo 'Can\'t access remote file time.<br />';                $remotetime = $localtime +1;}   $fp = fopen($localfile, 'w');            if(!$success = ftp_fget($conn, $fp, $remotefile, FTP_BINARY)){                echo 'Error: Could not download file';                ftp_quit($conn);该代码无法获得服务器文件的时间,也无法下载。真是奇怪,请指点。 


回复讨论(解决方案)

var_dump($remotetime);
看看有什么

有登录ftp吗? ftp_login($conn,$user, $password);  

有登录ftp吗? ftp_login($conn,$user, $password);  


$result = @ftp_login($conn, $user, $password);
        if(!$result){
            echo  "Error: Could not log on as $user
";
            ftp_quit($conn);
            exit;
        }
是有的,但是登录失败。这个用户名和密码要怎么写? firefox的ftp下载并不需要用户名和密码,但是ftp_login却要求需要用户名和密码的。我不知道怎么弄,请指点,在oschina提问他们都没理我,可能是觉得问题太低级了。。

var_dump($remotetime);
看看有什么


无法使用ftp_login登录。。 firefox的ftp下载并不需要用户名和密码,但是ftp_login函数却要求需要用户名和密码的。我不知道怎么弄,请指点,在oschina提问他们都没理我,可能是觉得问题太低级了。。

和浏览器也没关系吧,那是浏览器记住了. 

ftp 是有匿名用户的

$url = 'ftp.mozilla.org';$ftp = ftp_connect($url); //连接 ftp 服务器ftp_login($ftp, 'anonymous', ''); //用匿名用户登录$list = ftp_nlist($ftp, '/'); //取得根目录的文件列表print_r($list);
Array(    [0] => /README    [1] => /index.html    [2] => /pub)

如果已知 ftp 的目录结构,可以使用
file_get_contents 读
file_put_contents 写

如果已知 ftp 的目录结构,可以使用
file_get_contents 读
file_put_contents 写


,你好,我听从你的建议,发现运行我的php浏览器加载了很久很久,显示一个空白页面。
你的代码我也相信绝对没有问题,但是也显示空白页面,请问该怎么解决,应该不是代码的问题。
我的系统Debian + Netbeans + Netbeans 内置Php,浏览器是iceweasel

你的 ftp 扩展加载了吗?

我的代码绝无问题,你可以用浏览器访问 ftp://ftp.mozilla.org
速度慢是很正常的

你的 ftp 扩展加载了吗?

我的代码绝无问题,你可以用浏览器访问 ftp://ftp.mozilla.org
速度慢是很正常的


你好,版主,我的ftp是开启状态,我截图你看看 。

获取服务器数据的好像都不能用之类的,就像你这个代码也显示空白页。。

你的 ftp 扩展加载了吗?

我的代码绝无问题,你可以用浏览器访问 ftp://ftp.mozilla.org
速度慢是很正常的



我尝试链接其他站,却得出如下结果,无法获取服务器文件时间,也无法下载文件
Mirror Update Connected to ftp.debian.org.
Logged in as anonymous
Checking file time...
Local file last updated14:02 24-May-2014
Can't access remote file time.
Getting file from server...
Error: Could not download file
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn