المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Cannot upload chinese named file into Ftp server.



C# Programming
10-29-2009, 07:12 AM
hi everyone,

I am facing big problem in Ftp upload function.

When I run following code for english named file uploading It's ok. No problem. But when i try for chinese named file. I got this error message.
"The remote server returned an error: (550) File unavailable (e.g., file not found, no access)."

Let me know if you have solution for me. Thanks in advance. http://www.barakasoft.com/script/Forums/Images/smiley_smile.gif

~~ This is my source code ~~

// Get the object used to communicate with the server.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("XXX" + Path.GetFileName(this.txtUploadFile.Text));
request.Method = WebRequestMethods.Ftp.UploadFile;

// This example assumes the FTP site uses anonymous logon.
request.Credentials = new NetworkCredential ("XXX","XXX");
request.UseBinary = true;
request.UsePassive = false;
request.KeepAlive = false;

// Copy the contents of the file to the request stream.
StreamReader sourceStream = new StreamReader(this.txtUploadFile.Text);
byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());

sourceStream.Close();
request.ContentLength = fileContents.Length;

Stream requestStream = request.GetRequestStream(); // Error occurring in here

requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();

FtpWebResponse response = (FtpWebResponse)request.GetResponse();


Richard