首都機能移轉 (2) 歌詞 (2) 靠北文 (40) 戲言 (30) 糟糕 (7) ACG (23) Assembly (2) Boost (2) C (31) C++ (69) CMake (4) CSIE (67) Debian (34) Design_Pattern (2) Django (1) Eclipse (1) en_US (13) FFmpeg (3) FoolproofProject (26) FreeBSD (2) Git (4) GNU_Linux (65) IDE (5) Java (11) JavaScript (19) KDE (15) Khopper (16) KomiX (3) Kubuntu (18) Life (1) Lighttpd (2) Mac_OS_X (2) Opera (1) PHP (2) PicKing (2) Programing (21) Prolog (1) Python (7) QSnapshot (2) Qt (30) Qt_Jambi (1) Regular_Expression (1) Shell_Script (7) Talk (98) VirtualBox (7) Visual_Studio (13) Windows (18) zh_TW (36)

2011年11月8日 星期二

QNetworkAccessManager can not determine file size from Pure-FTPd

If you are using QNetworkAccessManager to download files from a Pure-FTPd server, the file sizes are always -1. This is cause by Qt, Pure-FTPd, and the FTP RFC spec.
Let's start from FTP RFC documentation. The very first FTP spec. is describe in RFC-959, and it doesn't describe how to retrieve size of files. The SIZE and MLSD command are describe in RFC-3659. Some FTP server may not support newer command.
For backward compatibility, QNetworkAccessManager sends HELP command first, and parse available commands to determine whether the server supports SIZE or not. But the response of HELP command is not strictly describes in RFC, so Pure-FTPd just prints a really simple help message, which doesn't mention useful command. There is a command FEAT to list all supported command, but it was appeared in RFC-2389.
For now (Qt 4.7.4), the best solution is to use QFtp. IMAO, QNetworkAccessManager is not really a general solution for both HTTP and FTP.