php 網頁ftp 代碼
<?php
$ftpserver="127.0.0.1";
$ftpport="21";
$ftpuser="anonymous";
$ftppassword="";
if($_POST)
{
$action=$_POST[action];
switch($action)
{
case "open":
case "change":
$ftpserver=$_POST[ftpserver];
$ftpport=$_POST[ftpport];
$ftpuser=$_POST[ftpuser];
$ftppassword=$_POST[ftppassword];
$ftp=@ftp_connect($ftpserver,$ftpport);
if(!$ftp){ echo "連接FTP服務器".$ftpserver."的端口".$ftpport."失敗";exit;}
$rs=@ftp_login($ftp,$ftpuser,$ftppassword);
if(!$rs){ echo "用戶名或密碼錯誤,連接FTP服務器失敗";exit;}
$curDir=$_POST[curDir];
if($curDir=="") $curDir="/";
if($curDir=="/")
{
$parentDir="/";
}else{
if(strrpos($curDir,"/")==0)
{
$parentDir="/";
}else{
$parentDir=substr($curDir,0,strrpos($curDir,"/"));
}
}
$arr=ftp_rawlist($ftp,$curDir);
if(count($arr)>1)
{
foreach($arr as $val)
{
if($curDir=="/")
{
$val="/" . trim(strrchr($val," "));
}else{
$val=$curDir . "/" . trim(strrchr($val," "));
}
$file_size=ftp_size($ftp,$val);
if($file_size==-1)
{//為目錄
$dirlist[]=str_replace("\","/",$val);
}else{
$filelist[]=str_replace("\","/",$val);
}
}
}
break;
case "close":
break;
}
}
下面來看看WEB頁面形式了.
?>