php ftp相关api

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/buyueliuying/article/details/82387739
    public function actionFtp()
    {
        $rootPath = Yii::getAlias('@root');
        $remote_file = 'test.txt';
        $local_file = $rootPath . '/test.txt';
        return $this->ftpPut($remote_file,$local_file);
    }

    public function ftpPut($remote_file,$local_file)
    {
        $host = '192.168.45.14';
        $user = 'username1';
        $password = 'pwd1';
        $port = 8989;
        //连接ftp服务器
        $conn = ftp_connect($host,$port);
        if(!$conn){
            echo 'Error: Could not connect to ftp server';
            exit;
        }

        //登陆ftp服务器
        $result = ftp_login($conn, $user, $password);
        if(!$result){
            echo "Error: Could not log on as $user";
            ftp_quit($conn);
            exit;
        }
        //被动模式
        ftp_pasv($conn,true);
        //查看目录
        //$r = ftp_nlist($conn,'.');
    //上传
        $result = ftp_put($conn,$remote_file,$local_file,FTP_BINARY);
        //关闭ftp
        ftp_close($conn);
        return $result;
    }
展开阅读全文

没有更多推荐了,返回首页