Handling Accented Characters in Filenames w/ IIS 7.5 FTP

To handle accented characters in filenames correctly, the FTP client must know what character encoding is used to represent these characters (such as utf-8, iso-8859-1, etc.). The Ftp2.DirListingCharset property indicates the character encoding to be used when interpreting the bytes of a filename (in a directory listing). By default, it is set to “ANSI”, which is another name for the default multi-byte (non-Unicode) charset of the computer. When connecting to an FTP server, if the server indicates it supports the “UTF8” feature, the DirListingCharset property will be implicitly set to “utf-8”. (You may check the value of the DirListingCharset after connecting to see what it contains.)

There has been some trouble with IIS 7.5 FTP.

It turns out that IIS 7.5 FTP has a new UTF 8 advanced option and when I set this to false, all accented characters appears correctly if the DirListingCharset remains at it’s default value.

In this case, it must be that the IIS 7.5 FTP server does not indicate it supports “UTF8” feature, and the DirListingCharset remains at its default  value of “ANSI” and the FTP server sends ANSI characters.  Since both are in agreement, there is no problem.

If this option is set to utf8, whether we set DislistingCharset or not, we don’t get the accented characters.

It is probable that that IIS 7.5 FTP still did not indicate that it supports the “UTF8” feature, and after connecting the DirListingCharset is implicitly set to ANSI.  The solution is to force the DirListingCharset to “utf-8” by setting this property after connecting.