I need to create file or directory on ftp via C# (in Unity engine). I tried to upload the file this way:
public void upload(string remoteFile, string file_content)
{
try
{
string address = host + @"/текст.txt";
Debug.Log(address); // gives a normal address in Unicode
ftpRequest = (FtpWebRequest)FtpWebRequest.Create(address);
ftpRequest.Credentials = new NetworkCredential(user, pass);
ftpRequest.UseBinary = true;
ftpRequest.UsePassive = true;
ftpRequest.KeepAlive = true;
ftpRequest.ContentLength = file_content.Length;
ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;
byte[] byteBuffer = System.Text.Encoding.Unicode.GetBytes(file_content);
try
{
using (ftpStream = ftpRequest.GetRequestStream())
{
ftpStream.Write(byteBuffer, 0, byteBuffer.Length);
Debug.Log(Convert.ToString(byteBuffer));
}
}
catch (Exception ex)
{
ErrorScene.error = "Local Error: 1. " + ex.ToString(); SceneManager.LoadScene("ErrorScene", LoadSceneMode.Single);
}
ftpStream.Close();
ftpRequest = null;
}
catch (Exception ex)
{
ErrorScene.error = "Local Error: 2. " + ex.ToString(); SceneManager.LoadScene("ErrorScene", LoadSceneMode.Single);
}
return;
}
And after this function call in ftp creates a file named ?????.txt.
Similarly with directories.
Is there a way to do this?
Thanks in advance.