当前位置 : 主页 > 网络编程 > PHP >

通过php的ftp函数上传文件

来源:互联网 收集:自由互联 发布时间:2021-07-03
//ftp,使文件传到服务器上protected function ftp_send($des,$src){ $ftp_ip = 'ip地址'; $ftp_user = 'ftp用户名'; $ftp_pass = 'ftp密码'; $conn_id = ftp_connect($ftp_ip) or die("Couldn't connect to $ftp_ip"); if(@ftp_login($conn
 
//ftp,使文件传到服务器上
protected function ftp_send($des,$src)
{
    $ftp_ip   = 'ip地址';
    $ftp_user = 'ftp用户名';
    $ftp_pass = 'ftp密码';
     
    $conn_id = ftp_connect($ftp_ip) or die("Couldn't connect to $ftp_ip");

    if(@ftp_login($conn_id, $ftp_user, $ftp_pass)) 
    {
         
        $path = dirname($des);
         
        if (!ftp_chdir($conn_id, $path)) 
        {
            ftp_mkdir($conn_id,$path);
        }
         
        $upload = ftp_put($conn_id,$des,$src,FTP_BINARY);
        if($upload)
        {
            ftp_close($conn_id);
        }
        else
        {
            exit('ftp error!');
        }
        
    } 
    else
    {
        echo "Couldn't connect as $ftp_user\\n";
        exit;
    }
     
}
 
网友评论