Я написал этот скрипт загрузки ftp для единства. Он следует по пути к текстовому файлу и загружает этот текст на FTP-сервер. Моя проблема в том, что он не работает, хотя я не получаю исключений.
На мой второй вопрос: есть ли способ проверить соединение с сервером?
Вот код :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.Net;
using System.IO;
using System.Diagnostics;
public class FTPUploader : MonoBehaviour
{
public string FTPHost = "ftp://files.000webhost.com";
public string FTPUsername = "User";
public string FPTPassword = "pass";
public string FilePath;
public void UploadFtp(int drinkNumber) //Klasse zum senden der Information über das Getränk zum FTP Server
{
if(drinkNumber == 1)
{
FilePath = Application.dataPath + "/FtpFiles/AppleJack.txt";
}else if (drinkNumber == 2)
{
FilePath = Application.dataPath + "/FtpFiles/Caipirinha.txt";
}else if(drinkNumber == 3)
{
FilePath = Application.dataPath + "/FtpFiles/VodkaO.txt";
}else if(drinkNumber == 4)
{
FilePath = Application.dataPath + "/FtpFiles/Tequila.txt";
}
UnityEngine.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, FPTPassword);
client.UploadFileAsync(uri, "STOR", FilePath);
}
void OnFileUploadProgressChanged(object sender, UploadProgressChangedEventArgs e)
{
UnityEngine.Debug.Log("Uploading Progreess: " + e.ProgressPercentage);
}
void OnFileUploadCompleted(object sender, UploadFileCompletedEventArgs e) //Debugging Tool um den Uploadzustand abzufragen
{
UnityEngine.Debug.Log("Upload Completed");
}
// Start is called before the first frame update
void Start()
{
UnityEngine.Debug.Log("FTPLoader Started");
UploadFtp(1);
}
// Update is called once per frame
void Update()
{
}
}