PDA

View Full Version : Reading file's content from ftp.



betees
19th November 2013, 16:04
Hi.

I'm using Qt 4.4.3 and try to read file's content from ftp server and show it with QTextEdit.


QBuffer file;
file.open(QIODevice::ReadWrite | QIODevice::Text);
file.setObjectName(fileName);

ftp->setTransferMode(QFtp::Passive);
ftp->connectToHost("192.168.10.17", 21);
ftp->login();
ftp->get(fileName, &file);

QString lines;
QTextStream in(&file);
while (!in.atEnd()) {
lines = in.readAll();
textEdit->setText(lines);
}

file.close();
ftp->close();

Above code shows nothing. I mean, textEdit is empty.

Outputs from ftp server are:

RETR test.diag
150 Opening data connection
Successfully sen file 'c:\ftproot\test.diag' (1112129 B sent)
226 transfer complete

And from my console:

Command Finished! Id:1-Status:0
Connection State Changed->1 Status: Host Lookup
Connection State Changed->2 Status: Connecting
Connection State Changed->3 Status: Connected
Command Finished! Id:2-Status:0
Connection State Changed->4 Status: Login
Command Finished! Id:3-Status:0
Transferred Data: 0
Remaining: 1112129
...
Transferred Data: 1112129
Remaining: 1112129
Connection State Changed->0 Status: Unconnected
Connection State Changed->5 Status: Closing

Any ideas what am I missing here?

anda_skoa
19th November 2013, 16:29
QFtp::get() is an asynchronous operation.

You have to wait for it to finish before you attempt reading the output buffer. See QFtp::commandFinished()

Cheers,
_

betees
20th November 2013, 09:15
Of course, thanks!