php的ftp函数简单应用
<?
$ftp_server="192.168.1.127";
$ftp_user = "foo";
$ftp_pass = "bar";
//连接ftp服务器
$con=ftp_connect($ftp_server);
//发送用户名和密码
ftp_login($con,$ftp_user,$ftp_pass);
//取得服务器的系统类型
ftp_systype($con);
//列出文件
$filelist=ftp_nlist($con,"/");
foreach ($contents as $entry) {
echo $entry, "<br />\n";
}
//下载文件
$local_file = 'local.zip';
$server_file = 'server.zip';
$down=ftp_get($con,$local_file,$server_file,FTP_BINARY);
if(!$down){
echo "no!";
}else{
echo "ok!";
}
//获得当前路径
echo ftp_pwd($con);
echo "<br>";
//改变路径
ftp_chdir($con,"somedir");
echo ftp_pwd($con);
//返回刚才的目录
ftp_cdup($con);
echo ftp_pwd($con);
//创建文件夹,删除的函数为ftp_rmdir($con,$dir)
$mkdir=ftp_mkdir($con,"test");
//上传文件
ftp_put($con,$destination_file, $source_file,FTP_ASCII);
//上传一个已经打开的文件到 FTP 服务器
$file = 'somefile.txt';
$fp = fopen($file, 'r');
ftp_fput($con, $file, $fp, FTP_ASCII)
//关闭ftp连接
ftp_close($con);
?>