0

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.

levonog
  • 19
  • 1
  • Can you create such file on the server using any standalone FTP client? Show us its log file! And even if you can, can you upload a file with letters from a different alphabet than yours (e.g. Japanese)? To prove that Unicode is being used. – Martin Prikryl Apr 30 '17 at 19:29
  • Hi Martin! Yes, I can create directory with unicode characters in name manually. And I tried to create folder also in armenian, and retrieved the same result. Re log file, I can't find it, maybe logging on the server is disabled. Thank you for your answer, sorry for late notice. – levonog May 01 '17 at 20:24
  • So show us client log. As well as [FtpWebRequest log](http://stackoverflow.com/q/9664650/850848) - For me your code works good, both with Cyrillic and Armenian script. – Martin Prikryl May 02 '17 at 06:08

0 Answers0