通过C#在名称上使用unicode字符上传文件或在ftp上创建目录

时间:2017-04-30 10:33:14

标签: c# unity3d unicode ftp

我需要通过C#(在Unity引擎中)在ftp上创建文件或目录。我尝试以这种方式上传文件:

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;
}

在此函数调用之后,ftp会创建一个名为?????。txt。

的文件

与目录类似。

有办法做到这一点吗?

提前致谢。

0 个答案:

没有答案