locked
Working with FtpWebRequest and Special Characters RRS feed

  • Question

  • Hi,

    I have been working with FtpWebRequest perfectly, downloading, uploading, etc., until I found myself into trouble when the file name has special characters like this:  Escñóqqwñá#.jpg

    and it just doesn't work, no matter what, I always get the "error 550 file unavailable" when trying to download, so I tried to rename the file and trying to access the file name with httputility.urlencode(str), but I can't still modify the name so I can download it.

    Dim fReq As FtpWebRequest = WebRequest.Create(ftp://192.168.254.1/2203/Escñóqqwñá#.jpg)
    fReq.Credentials =
    New NetworkCredential("XXXXX", "XXXXXX")
    fReq.Method = WebRequestMethods.Ftp.Rename
    fReq.RenameTo = "
    ftp://192.168.254.1/2203/Escnoqqwna_.jpg

    Dim fRes As FtpWebResponse = fReq.GetResponse()

    Any help would be appreciated.

    Thanks in advance.

    George.

    Saturday, November 18, 2006 2:22 PM

Answers

  • Well, I couldn't find any Chinesse programmer, so I had to come up this solution, it works just great !!!

    Dim xftpRequest As FtpWebRequest
    Dim xftpResponse As FtpWebResponse
    Dim MyURI As Uri

    MyURI = New Uri(ftp://192.168.254.1/mydir & "/" & System.Web.HttpUtility.UrlEncode("Esc#áíroieurûrtóíé.jpg"))
    xftpRequest =
    CType(WebRequest.Create(MyURI), FtpWebRequest)
    xftpRequest.Credentials =
    New NetworkCredential("abcde", "12345")
    xftpRequest.Method = WebRequestMethods.Ftp.Rename
    xftpRequest.RenameTo =
    "Esc123456789.jpg"
    xftpResponse = CType(xftpRequest.GetResponse, FtpWebResponse)

    I hope it can help lots of people, because THERE IS NOT ANY INFORMATION on the net about renaming a file with ftp.

    Regards.

    George



    Monday, November 20, 2006 10:32 AM

All replies

  • So True,

    I tried the same thing and faced the same problem. But there is something we can do here. I did a little test, I wrote the same code and had the same problem. It worked fine with normal name but it didnot work with the name you specidifed. Then I tryed to open that file using Internet Explorer and it showed me file name in Address bar to be "Escqqw%23.png". And used this name in my application and it worked quite fine! So the conclusion is that there would be something to parse the file names to be a correct uri which can work with this situation. I'm sorry I did not have time to do some more test on this. But you can dig it up to see how to change the file name to be a correct uri before you reuqest something on that file to the Server.

    See Uri class if it helps! Or ask some Chinese programmer, because they must have faced this problem 1000 times because their file names include the most annoying characters :P. Or some expert from System.Net namespcace can help you because I belive this issue would have been raised 1000s of time and it would be answered in the same number of times!

    .Net base class library is not pnly for people who use English but its a platform for everyone in the world to have software in their own language!

    If you get some solution please do not forget to share it with me here!

    Thank you soo much!

    Best Regards,

    Rizwan

    Sunday, November 19, 2006 2:44 PM
  • Well, I couldn't find any Chinesse programmer, so I had to come up this solution, it works just great !!!

    Dim xftpRequest As FtpWebRequest
    Dim xftpResponse As FtpWebResponse
    Dim MyURI As Uri

    MyURI = New Uri(ftp://192.168.254.1/mydir & "/" & System.Web.HttpUtility.UrlEncode("Esc#áíroieurûrtóíé.jpg"))
    xftpRequest =
    CType(WebRequest.Create(MyURI), FtpWebRequest)
    xftpRequest.Credentials =
    New NetworkCredential("abcde", "12345")
    xftpRequest.Method = WebRequestMethods.Ftp.Rename
    xftpRequest.RenameTo =
    "Esc123456789.jpg"
    xftpResponse = CType(xftpRequest.GetResponse, FtpWebResponse)

    I hope it can help lots of people, because THERE IS NOT ANY INFORMATION on the net about renaming a file with ftp.

    Regards.

    George



    Monday, November 20, 2006 10:32 AM
  • I'm happy you dug it and atleast done! Welldone!

    Best Regards,

    Rizwan

    Monday, November 20, 2006 5:32 PM