Reading file's content from ftp.
Hi.
I'm using Qt 4.4.3 and try to read file's content from ftp server and show it with QTextEdit.
Code:
file.setObjectName(fileName);
ftp
->setTransferMode
(QFtp::Passive);
ftp->connectToHost("192.168.10.17", 21);
ftp->login();
ftp->get(fileName, &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:
Quote:
RETR test.diag
150 Opening data connection
Successfully sen file 'c:\ftproot\test.diag' (1112129 B sent)
226 transfer complete
And from my console:
Quote:
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?
Re: Reading file's content from ftp.
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,
_
Re: Reading file's content from ftp.