php中FTP函数ftp_connect、ftp_login与ftp_chmod用法
本文实例讲述了php中FTP函数ftp_connect、ftp_login与ftp_chmod用法。分享给大家供大家参考。具体方法如下:
ftp_connect()函数建立一个新的ftp连接,若成功,则返回一个连接标识,否则返回false.
语法:ftp_connect(host,port,timeout),实例代码如下:
$file='public_html/index.php'; //定义文件 $conn_id=ftp_connect($ftp_server); //连接到指定的ftp服务器 $login_result=ftp_login($conn_id,$ftp_user_name,$ftp_user_pass); //用指定用户名登录 if(ftp_chmod($conn_id,0644,$file)!==false) //设置文件的模式 { echo"$filechmodedsuccessfullyto644n"; //输出信息 } else { echo"couldnotchmod$filen"; //如果设置失败输出信息 } ftp_close($conn_id); //关闭ftp连接
ftp_chmod()函数设置ftp服务器上指定文件的权限,若成功,则该函数返回新的权限,否则返回false.
语法:ftp_chmod(ftp_connection,mode,file),代码如下:
$ftp_server="ftp.jb51.net"; //定义ftp服务器 $ftp_user="foo"; //定义用户名 $ftp_pass="bar"; //定义用户对应的密码 $conn_id=ftp_connect($ftp_server)ordie("couldn'tconnectto$ftp_server");//连接到指定ftp服务器 if(@ftp_login($conn_id,$ftp_user,$ftp_pass)) //如果成功登录 { echo"connectedas$ftp_user@$ftp_servern"; //输出相应信息 } else { echo"couldn'tconnectas$ftp_usern"; //输出不能登录的信息 }
ftp_login()函数登录ftp服务器,若成功则返回true,失败则返回false并发出一个警告.
语法:ftp_login(ftp_connection,username,password)
希望本文所述对大家的PHP程序设计有所帮助。