Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QFtp with unicode



  • I am having trouble with QFtp and unicode file names. Everything looks fine up to where I call .put(), but when the file arrives at the destination, the name is a lot of question marks where the unicode characters are. (???? ????abc.xyz)

    Is this happening in the Qt call or is there something on the FTP server that isn't translating it correctly?



  • How do you check the file name? What is the encoding of the filename? What encoding do you use when retrieving the data?



  • I was following along in the debugger (VS). I tried using toUTF8() and that seems to work with the server I am testing against, but we are not sure that this is reliable to use with any old FTP server out there.



  • Check your server's OS and web server application to make sure it allows unicode filenames on ftp.



  • Exactly. The server will probably be fine, since the filename essentially is just a character array. It is the client you should worry about. If you really want to keep backwards compatibility with non-unicode clients, you should only allow ASCII names. Obviously this is starting to become less and less of an option.



  • The problem is that we have no control over the servers (user chooses it), and users have file names that work on their local systems in unicode. They may or may not be using the FTP option. I don't want to break something that works most of the time to have compatibility with only a few servers.

    Thanks for the replies - looks like I need to do more testing with different types of servers.



  • I'm not sure about the protocol itself, but I simply think QFtp is not Unicode-safe.

    See for instance

    and the last line is
    @
    commandSocket.write(currentCmd.toLatin1());
    @



  • [quote author="khend" date="1294331766"]Thanks for the replies - looks like I need to do more testing with different types of servers.[/quote]Again, it is probably the clients that need checking. The servers are very likely to be ignorant of encoding (it really doesn't care which number represents which character).

    In that line it is very likely that QFtp uses the toLocal8Bit, toAscii or codecForCStrings for the file transfer. You could try setting the latter to UTF-8, which should result in proper unicode strings on the other side. If that fails, try using QNetworkAccessManager instead of QFtp, which is the recommended thing to do anyway.


Log in to reply