Created
June 12, 2019 01:46
-
-
Save as8190255/a916085392f39b9be6bbde09eb8c58c8 to your computer and use it in GitHub Desktop.
Unity C#文件发送到FTP服务器
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment