R
R
RoboSloNE2012-03-15 01:20:40
Qt
RoboSloNE, 2012-03-15 01:20:40

How to upload a file to an FTP server in Qt?

I looked through a lot of mana, but I did not find the right one:
How to upload a local file to a remote FTP server?
So far I have this piece:

// Отправка файла по FTP<br/>
 report.open(QIODevice::ReadOnly);<br/>
<br/>
QFtp *ftp = new QFtp;<br/>
 connect(ftp, SIGNAL(done(bool)), this, SLOT(close()));<br/>
<br/>
ftp-&gt;connectToHost(&quot;10.1.2.2&quot;, 21);<br/>
 ftp-&gt;login(&quot;login&quot;, &quot;password&quot;);<br/>
 ftp-&gt;cd(&quot;REPORTS&quot;);<br/>
<br/>
//??? Вот тут по идее должен быть ftp-&gt;put()<br/>
<br/>
report.close();

The report itself is a QFile that needs to be uploaded to the server.
How to write correctly?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
mik_os, 2012-03-15
@RoboSloNE

put expects QIODevice , and QFile inherits from it, which means:
ftp->put(&report, report.fileName());
Qt has very good documentation, don't be afraid to use it.

M
mik_os, 2012-03-15
@mik_os

The function returns a unique identifier which is passed by commandStarted() and commandFinished().
Remember the file-identifier pair, catch the commandFinished signal, close it and release resources.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question