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

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

WBOY
WBOYOriginal
2016-06-13 11:58:00933browse

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

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

------解决方案--------------------
有登录ftp吗? ftp_login($conn,$user, $password);  

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

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