Unity连接FTP服务器,点击按钮下载

由于项目的需要,用FileZilla server做了个本地的FTP服务器,在Unity端对打包好的场景进行下载,并自动加载该场景,实现了程序和场景的分离,让APK的文件小了很多。原代码如下:(因为是在网上找的,并加以改动,所以有一部分代码是没用到的)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
using System.IO;
// 添加命令空间
using System.Net;
using System.Text;


public class GetSceneFromFTP : MonoBehaviour {
    private const int ftpport = 21;
    private string ftpUristring = null;
    private NetworkCredential networkCredential;
    public string ftppath;
    private string currentDir = "/";
    public string downname;
    public GameObject LoginInformation;//显示是否登录成功
    public GameObject SceneListMenu;
    void Start()
    {
    }
    #region 与服务器的交互
    //创建FTP连接
    public FtpWebRequest CreateFtpWebRequest(string uri, string requestMethod)
    {
        FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(uri);
        request.Credentials = networkCredential;
        request.KeepAlive = true;
        request.UseBinary = true;
        request.Method = requestMethod;
        return request;
    }
    // 获取服务器返回的响应体
    public FtpWebResponse GetFtpResponse(FtpWebRequest request)
    {
        FtpWebResponse response = null;
        try
        {
            response = (FtpWebResponse)request.GetResponse();
            return response;
        }
        catch (WebException ex)
        {
            return null;
        }
    }
    #endregion
    // 登录服务器事件
    public void btnlogin_Click()
    {
        ftpUristring = "ftp://" + ftppath;
        networkCredential = new NetworkCredential("admin",

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值