edtFTPnet/PRO - Secure FTP component for .NET | Free Trial | Pricing

How to use different character encodings

Officially the FTP protocol (RFC959) only supports 7-bit ASCII characters. This means that file and directory names transferred across the control channel can only be ASCII.

Fortunately, most FTP servers do support at least 8-bit ASCII. However there is no standard for what extended ASCII encoding is to be used. As a result, the meaning of characters 0 to 127 is well defined, but the meaning of characters 128 to 255 varies from one server to the other. One server might interpret character 193 as an accented A, whereas another might interpret it as an accented E.

By default, FTPConnection (and its subclasses) supports 7-bit ASCII. If it encounters a character whose code is 128 to 255 it will represent it as a question mark. The CommandEncoding property allows the developer to select an 8-bit character encoding that matches that of the server. Unfortunately many servers do not state what 8-bit ASCII character set they are using, so it is often necessary to use trial and error to find out. Some common character encodings to try for western European languages are Windows-1252 and ISO-8859-1.

For example, to set the command encoding to Windows-1252:

ftpConnection.CommandEncoding = Encoding.GetEncoding("Windows-1252");

For Chinese, try using an encoding such as big5.