Stream Me Up, Scotty! (part 1)
PHP4 comes with a bunch of new functions designed to allow FTP connections over the Web. This article explores the new FTP functions, together with an example of how they can be used to build a browser-based FTP client.http://www.devshed.com/Server_Side/PHP/Stream/Stream1/page1.html

解决方案 »

  1.   

    it seems that the FTP functions do not quite suit my requirements.
    i just want to redirect the client user to the FTP server and login automatically, but not wanna download the files to the HTTP server and then output to the clients, this could use a lot of bandwidth, and i want to save my host's bandwidth.
      

  2.   

    if you do redirection to the ftp server, the ftp server will ask the browser for authentication information, so you are in a dilemma
      

  3.   

    我的做法是:
    直接写地址比如
    ftp://ftp.xxx.com/*************
    可以参考我做的
    http://finefood.math.sdu.edu.cn/softidx.php关于路径我是用ftp函数得到的
    如果你的是一个具体的地址,直接写,如果是想把所有东西都写上去
    <?
      include ("./search_ini.php");
      include ("./class.php");
    ###################################################
    #程序:              FTP搜索引擎主文件            #
    #文件:              search.php                   #
    #姓名:              网络骑士                     #
    #所用技术:           php&mysql                    #
    #版本:              v1.0                         #
    #联系:              [email protected] #
    ###################################################$ftp_stream=ftp_connect($ftp_server,21);
    $login=ftp_login($ftp_stream,"$username","$userpassword");
    if(!$login||!$ftp_stream){
                             echo "cannot connect to $ftp_server";
                             echo "try again";
                             }
    else
                             {
                             echo "<font color=".$color." size=+3 >connect to $ftp_server<br>CONGRATULATIONS!</font><br>";
                             }
                             $link=mysql_pconnect("$localhost","$datauser","$datapassword");
                             mysql_select_db("$database",$link);
    $this=ftp_pwd($ftp_stream);
    $this=@ftp_chdir($ftp_stream,"");$result=ftp_nlist($ftp_stream,$this);
    for ($i=0;$i<=count($result);$i++)
    {
    if (is_dir($result[$i]))
     {
     happy($ftp_stream,$result[$i],$link);
     }
     else {echo $result[$i]."<br>";
      $basename=basename($result[$i]);
      $file=explode(".",$basename);
      $id=$i;
      $today=(date("Y")."-".date("m")."-".date("d"));
      $content="$result[$i]";
      $time=date("H:i:s");
      $query="INSERT INTO realfly VALUES ( '$file[0]', '$id', '$today', '$time', '$content');";
      mysql_query($query,$link);
      }
    }
    ?>
    下面 是search.ini文件,当然你命名的时候要命名成.php文件------为了安全
    <?
    //ftp信息
    $ftp_server="ftp.math.sdu.edu.cn";
    $username="xxx";
    $userpassword="xxxxxxxxxxxx";
    //数据库信息
    $localhost="localhost";
    $datauser="root";
    $datapassword="xxxxxxxxxxxx";
    $database="xxxxxxxxxxxxxx";//数据表建立信息
    // CREATE TABLE tablename (
    //   name text NOT NULL,
    //   id tinyint(4) unsigned NOT NULL auto_increment,
    //   date date DEFAULT '0000-00-00' NOT NULL,
    //   time time DEFAULT '00:00:00' NOT NULL,
    //   content longtext NOT NULL,
    //   KEY id (id)
    // );?>
    <?
    ###################################################
    #程序:              FTP搜索引擎递归函数文件      #
    #文件:              search.php                   #
    #姓名:              网络骑士                     #
    #所用技术:           php&mysql                    #
    #版本:              v1.0                         #
    #联系:              [email protected] #
    ###################################################function happy($ftp_stream,$directory,$link){ if(is_dir($directory)) {  //$today=(date("Y")."-".date("m")."-".date("d"));  //$content=$directory;  //$time=date("H:i:s");  //$query="INSERT INTO realfly VALUES ('', '', '$today', '$time', '$content');";  //mysql_query($query,$link);  //$color="FF3399";  //echo  "<font color=".$color."size=2>".$directory."</font><br>";  $result=ftp_nlist($ftp_stream,$directory);  for ($j=0;$j<=count($result);$j++){                                       happy($ftp_stream,$result[$j],$link);                                    } } else {  $basename=basename($directory);
      $file=explode(".",$basename);  $id=$i++;  $today=(date("Y")."-".date("m")."-".date("d"));
      $content=$directory;  //$content4=$directory;  $time=date("H:i:s");  $query="INSERT INTO realfly VALUES ('$file[0]', '$id', '$today', '$time', '$content');";  mysql_query($query,$link); echo $directory."<br>";
     }}?>以上代码如需转载,请注明出处
      

  4.   

    查询页面
                      
    <html>
    <head><title>搜索页面</title></head>
    <body>
     <FONT size=4>欢迎使用FTP高级搜索
    <A href="mailto:[email protected]">  (如有技术上的问题请联系shakespeare)</A></FONT></PRE>
                <FORM action=./gogogo.php method=post name=form1><PRE>windows工具   <INPUT name=query1 value=请输入>   <INPUT name=Submit type=submit value=go>      <INPUT name=tb type=hidden value=windows></PRE></FORM>
                <FORM action=./gogogo.php method=post name=form2><PRE>linux工具     <INPUT name=query1>   <INPUT name=Submit2 type=submit value=go>       <INPUT name=tb type=hidden value=linux>  </PRE></FORM>
                <FORM action=./gogogo.php method=post name=form3><PRE>操作系统      <INPUT name=query1>   <INPUT name=Submit3 type=submit value=go>     <INPUT name=tb type=hidden value=os>  </PRE></FORM>
                <FORM action=./gogogo.php method=post name=form4><PRE>书籍资料      <INPUT name=query1>   <INPUT name=Submit4 type=submit value=go>     <INPUT name=tb type=hidden value=book>        </PRE></FORM>
    </body>
    </html>
    查询处理页面
    <?############################################软件名:     FTP搜索引擎显示页面         ##版本:       v1.0                        ##所用技术:   php&mysql                   ##作者:       网络骑士                    ##联系方式:   [email protected]############################################//connect to database$link=mysql_pconnect("localhost","root","sql002fol") or die ("无法连接服务器,请稍后再试!");//select databasemysql_select_db("shakespeare",$link);//make query$query="select name,content from realfly where name='$query1' ";
    echo "您所查询的字段:        "; echo "$query1.<BR>";
    $i=0;
    $result=mysql_query($query,$link);
    if($result)
    {while(list($name,$content)=mysql_fetch_row($result))
      { echo "您所能查询到的结果:     ";
        $content3="ftp://ftp.math.sdu.edu.cn";
        $content2=stristr($directory,"/var/ftp");
        $content=$content3.$content2;
        echo "<a href=$content.>$content</a><BR>";
        $i++;
      }   } if($i==0)
                        {   $color="FF3399";
       echo  "<font color=".$color."  size=2>真是太神奇了,居然没有找到,呵呵~~,再试试!</font><br>";}
     else echo "恭喜,您要查找的东东找到了,赶快下载吧!.<br>";
        ?>
    以上代码如需转载,请注明出处
    浅妄薄见,望与斟酌
      

  5.   

    感谢骑上的代码。但是这个代码不是太符合我的要求。
    我是想既给ftp加帐号让客户直接从ftp服务器下载而不想让客户知道ftp的帐号密码。
    思归说得也对,看来是没办法可以这样转向而不把帐号密码显示出来了...苦阿
      

  6.   

    这个只是我做的初级的版本
    它有两个不足之处
    1:只能处理比较一般的FTP站点(文件书目在3万左右的,另外如果你的目录太深,比如我们那个BT的站长居然弄了个18层的目录,比较困难)/另附:这是我模仿北大天网的FTP搜索做的,当然功能远不能和它相比它是由几百个人做的项目。我的只适合于一般的搜索生成数据库关于这两个问题我已经想到了解决的办法
    1:可以模仿flashget的多线程下载的方式,如果目录过多,那么同时运行对每个目录进行搜索,只是忙着考试没有时间实现,所以停留在理论阶段
    to  pcdreama(峰幻) :
    这个基本上不可能,因为ftp是必须登陆的----即使是匿名-----不过有的时候在直接匿名登陆不可以的话,用flashget却能够下载东西,却不知道是什么原因浅妄薄见,望与斟酌
      

  7.   

    北大天网FTP的搜索应该不是用网络语言写的,肯定里面有个驻留程序不停搜索数据库的ftp,不断更新数据库,这个也是各搜索引擎的做法。这种做法我们用php不可能做到啦只能做到简化版 :)而多线程方式用php比较麻烦吧?应该要在html那个页面用多个iframe之类的东西实现这种多线程吧?不知你的想法是如何?我的那个要求再三思量下,都是觉得比较痛苦...没什么可能。 :~(
    匿名下载那里其实应该是因为服务器限制了用户数,而flashget刷多几次才连上的,因为flashget也是用标准的ftp协议,不会发生什么特殊情况啦。