分享

Unity 3D简单C#文件发送到FPT服务器示例脚本?

 鸿蛟家平 2019-09-06

即使你这样做,你也会收到错误消息:

The format of the URI could not be determined: blah blah blah

你的"ftp.byethost7.com";链接应该是"ftp://byethost7.com";

这是FTPUnity中的完整上传代码。

using UnityEngine;
using System.Collections;
using System;
using System.Net;
using System.IO;

public class Uploader : MonoBehaviour
{
    public string FTPHost = "ftp://byethost7.com";
    public string FTPUserName = "b7_18750253";
    public string FTPPassword = "xxx";
    public string FilePath;

    public void UploadFile()
    {
        FilePath = Application.dataPath + "/StreamingAssets/data.xml";
        Debug.Log("Path: " + FilePath);


        WebClient client = new System.Net.WebClient();
        Uri uri = new Uri(FTPHost + new FileInfo(FilePath).Name);

        client.UploadProgressChanged += new UploadProgressChangedEventHandler(OnFileUploadProgressChanged);
        client.UploadFileCompleted += new UploadFileCompletedEventHandler(OnFileUploadCompleted);
        client.Credentials = new System.Net.NetworkCredential(FTPUserName, FTPPassword);
        client.UploadFileAsync(uri, "STOR", FilePath);
    }

    void OnFileUploadProgressChanged(object sender, UploadProgressChangedEventArgs e)
    {
        Debug.Log("Uploading Progreess: " + e.ProgressPercentage);
    }

    void OnFileUploadCompleted(object sender, UploadFileCompletedEventArgs e)
    {
        Debug.Log("File Uploaded");
    }

    void Start()
    {
        UploadFile();
    }
}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多