Ftp create a filename with utf-8 chars such as greek, german etc

前端 未结 2 1459
温柔的废话
温柔的废话 2020-12-19 18:11

I am trying to create a file to an ftp server with the following code (where I also tried with UseBinary option true and false)

string username = \"name\";
s         


        
2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-19 18:18

    It is not enough for you just to encode your string as UTF8 and send it as filename to FTP server. In the past all FTP servers understood ASCII only and nowadays to maintain backward compatibility - even if they are Unicode aware - when they start they treat all filenemes as ASCII too.

    To make it all work you (your program) must first check what your server is capable of. Servers send their features after client connects - in your case you must check for FEAT UTF8. If your server sends that - it means it understands UTF8. Nevertheless - even if it understands it - you must tell it explicitly that from now on you will send your filenames UTF8 encoded and now it is the stuff that your program lacks (as your server supports utf8 as you've stated).

    Your client must send to FTP server the following OPTS UTF8 ON. After sending that you may use UTF8 or speak UTF8-ish (so to speak) to your sever.

    Read here for details Internationalization of the File Transfer Protocol

提交回复
热议问题