Skip to content

Instantly share code, notes, and snippets.

@as8190255
Created June 12, 2019 01:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save as8190255/a916085392f39b9be6bbde09eb8c58c8 to your computer and use it in GitHub Desktop.
Save as8190255/a916085392f39b9be6bbde09eb8c58c8 to your computer and use it in GitHub Desktop.
Unity C#文件发送到FTP服务器
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