即使你这样做,你也会收到错误消息: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();
}
}