locked
VB.Net FTP Library Problem about Uploading files which as Chinese Character on the file name. RRS feed

  • 問題

  • Hi

    I have used the read the link which introduce "Simple FTP Demo Application Using C~.Net 2.0" from the post in
    http://forums.microsoft.com/hongkong/ShowPost.aspx?PostID=3296589&SiteID=82

    It works very well, but Not i am having a problem about Uploading a file which has Chinese Character in the file name.

    The error I have received is The Remote server returned an error: (550) File unavailable (e.g., file not found, no access).

    Does it mean the FTP Server do not allow me to upload the file? I am using a English version of WinXP Pro's IIS 5.1 as developement purpose? if so it there any way I could config the IIS to make it to allow Chinese Character File?
    *I can create file with Chinese Characters as filename in the same window.

    Would it be a problem on the VB.Net?

    Thanks in advance.
    2008年5月29日 下午 04:04

解答

  • Hi Chi,

     

    I've tried your code in the follow environment
    Server:
    Chinese Windows XP w SP2 in Chinese Language + Serv-U FTP Server
    English Windows Vista w SP1 in Korean Language + IIS FTP Server
    Client:
    English Windows Vista w SP1 in Chinese Language

     

    all of them can work fine with upload file with chinese name, but fail in upload file with "korean" name. the reason is failed to convert command to 8 bit charset
    why korean is just want to make sure the issue is not gen from the server.

    since the korean filename may store in unicode(16 bit) in client machine, so please try a chinese enabled client machine and test your code again.

     

    Jacky

    2008年6月9日 上午 11:08
  • Hi Chi,

     

    Please confirm a setting in Control Panel > Regional and Language Options > Administrative > Current language for non-unicode program
    it should work if Chinese (Traditional, Hong Kong S.A.R./Taiwan)

     

    Jacky

    2008年6月9日 下午 12:49

所有回覆

  • Hi ChiYau and everyone,

     

    please correct me if my concept getting mistake.

     

    when you create a file throw FTP, the name will in ASCII encoding(Big 5/GB2312), if the OS language is not Chinese(in this case) it might get error, BUT when you create Chinese characters filename directly using Windows Explorer that's store in Unicode encoding.

     

    that's why when you "upload" a Chinese filename it will become monster / got error during the filename since it might become "%xx%xx%xx" or "???" that's generate error.

     

    hope it's help for you.

    2008年6月6日 上午 11:13
  • Hi Jacky

    Thanks for your information, do you know if there any configuration I can do on the windows to resolve that problem?

    Many thanks
    2008年6月6日 下午 05:54
  • just found this:

    http://topic.csdn.net/t/20060627/15/4846157.html

     

    try to use a streamwriter and set the encoding rather than use stream.write directly

     

    2008年6月6日 下午 06:10
  • Hi Jacky

    Thanks for  your information. I am not show where shall I use the streamwriter? Because I am trying to upload a file with chinese file name, I am not sure If i can use streamwrite to a ftp server.

    Another question, after I read the article, I just realise I have the same problem as the author, Which is not be able to display chinese character when I try to retrieve the directory from the FTP server.
    They have provided a solution which is to set the encoding. I tried UTF8 and ASCII, unfortunately, they do not work on my application. When I use unicode, it throw exception.

    <<Cannot access a disposed object.
    Object name: 'System.Net.Sockets.NetworkStream'.>>

    Could you let me know what encoding shall I use?

    Here it is the code for my upload function.
     
    Code Snippet

       Public Function UploadFile(ByVal filename As String) As Boolean
            Dim result As Boolean = False
            Dim fInfo As New FileInfo(filename)


            Dim myFTP As FtpWebRequest


            myFTP = FtpWebRequest.Create(New Uri(FTPAddress + "/" + fInfo.Name))
            myFTP.UseBinary = True
            myFTP.Credentials = New NetworkCredential(FTPUsername, FTPPW)
            myFTP.KeepAlive = False
            myFTP.Method = WebRequestMethods.Ftp.UploadFile

            myFTP.ContentLength = fInfo.Length

            Dim bufferLength As Int32 = 2048
            Dim contentLen As Int32 = 0
            Dim buffer(bufferLength) As Byte
            Dim fStream As FileStream
            fStream = fInfo.OpenRead

            Try
                Dim responseStream As Stream
                responseStream = myFTP.GetRequestStream
                contentLen = fStream.Read(buffer, 0, bufferLength)

                While (contentLen <> 0)
                    responseStream.Write(buffer, 0, contentLen)
                    contentLen = fStream.Read(buffer, 0, bufferLength)

                End While
                responseStream.Close()
                fStream.Close()
                result = True
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try

            Return result
        End Function



    Could you give me some suggestion about how could I Upload a file with Chinese Filename.

    Thanks in advance.
    2008年6月9日 上午 07:55
  • Hi Chi,

     

    I've tried your code in the follow environment
    Server:
    Chinese Windows XP w SP2 in Chinese Language + Serv-U FTP Server
    English Windows Vista w SP1 in Korean Language + IIS FTP Server
    Client:
    English Windows Vista w SP1 in Chinese Language

     

    all of them can work fine with upload file with chinese name, but fail in upload file with "korean" name. the reason is failed to convert command to 8 bit charset
    why korean is just want to make sure the issue is not gen from the server.

    since the korean filename may store in unicode(16 bit) in client machine, so please try a chinese enabled client machine and test your code again.

     

    Jacky

    2008年6月9日 上午 11:08
  • Hi Jacky

    Thanks very much for your help, it probably some setting not right on my Window XP Pro English Edition.
    <<so please try a chinese enabled client machine and test your code again.>>
    --> I can type, read chinese and create change characters' file name on my WinXP, does it mean it is chinese enabled? Or is there some setting I need to change to make it works properly?

    I am using English Windows XP Pro w SP3 + IIS FTP Server.

    Thanks a lot.
    2008年6月9日 上午 11:48
  • Hi Chi,

     

    Please confirm a setting in Control Panel > Regional and Language Options > Administrative > Current language for non-unicode program
    it should work if Chinese (Traditional, Hong Kong S.A.R./Taiwan)

     

    Jacky

    2008年6月9日 下午 12:49
  • Hi Jacky

    Thanks very much for your information. It works = )

    Many thanks
    2008年6月9日 下午 02:02