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?
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
- QFtp::put: http://qt.gitorious.com/qt/qt/blobs/master/src/network/access/qftp.cpp#line1875
- which calls http://qt.gitorious.com/qt/qt/blobs/master/src/network/access/qftp.cpp#line2210
- which calls http://qt.gitorious.com/qt/qt/blobs/master/src/network/access/qftp.cpp#line822
- which calls http://qt.gitorious.com/qt/qt/blobs/master/src/network/access/qftp.cpp#line1143
and the last line is
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). Thanks for the replies – looks like I need to do more testing with different types of servers.
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.