<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Simple ftp file transfer reconnect problem?]]></title><description><![CDATA[<p dir="auto">Hello,<br />
i write an small prg that transfer an file via ftp.<br />
i test the prg and get following error,<br />
if the username wrong first transfer get an user or password error 204,<br />
thats okay, if i retry the transfer with the same settings i get an timeout.</p>
<p dir="auto">why?</p>
<p dir="auto">@#include "include/Protocol/Ftp.h"<br />
#include "include/ConfigFile/ConfigFile.h"<br />
#include "include/Defines/Global.h"</p>
<p dir="auto">#include &lt;QUrl&gt;<br />
#include &lt;QNetworkAccessManager&gt;<br />
#include &lt;QFile&gt;<br />
#include &lt;QApplication&gt;</p>
<p dir="auto">Ftp::Ftp(ConfigFile &amp;config, QWidget *parent) :<br />
QWidget(parent), cf(config), reply(NULL)<br />
{<br />
manager  = new QNetworkAccessManager(0);<br />
connecttimer.setInterval(FTP_CONNECT_TIMEOUT);<br />
connect(&amp;connecttimer, SIGNAL(timeout()), this, SLOT(CheckConnection()));</p>
<p dir="auto">}</p>
<p dir="auto">void Ftp::GetFile(void)<br />
{<br />
if(!reply)<br />
{<br />
reply = manager-&gt;get(QNetworkRequest(QUrl("ftp://" +cf.GetftpUsername() +":" +cf.GetftpPassword() +"@" +cf.GetServerAddress().toString() +":" +QString::number(cf.GetftpPort()) +"/" +cf.GetProgramName() +OS_PRG_EXT)));<br />
qDebug() &lt;&lt; "#########" &lt;&lt; "reply == NULL" &lt;&lt; "#########";<br />
connect(reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(downloadinProgress(qint64,qint64)));<br />
connect(reply, SIGNAL(finished()), this, SLOT(replyfinished()));<br />
connect(reply, SIGNAL(readyRead()), this, SLOT(slotReadyRead()));<br />
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(slotError(QNetworkReply::NetworkError)));<br />
}</p>
<pre><code>connecttimer.start();

#if DEBUG_LEVEL_FTP &gt; LOG_ERRORS
     qDebug() &lt;&lt; this-&gt;metaObject()-&gt;className() &lt;&lt; "FTP: GetFile ";
#endif
</code></pre>
<p dir="auto">}</p>
<p dir="auto">void Ftp::CheckConnection(void)<br />
{<br />
#if DEBUG_LEVEL_FTP &gt; LOG_ERRORS<br />
qDebug() &lt;&lt; this-&gt;metaObject()-&gt;className() &lt;&lt; "CheckConnection";<br />
#endif</p>
<pre><code>connecttimer.stop();
reply-&gt;disconnect();

if(reply)
{
    if(reply-&gt;isFinished())
    {
        replyfinished();
        emit DownloadFinished(reply-&gt;error());

            emit StatusUpdate("No error");
    }
    else
    {
        qDebug() &lt;&lt; "reply-&gt;isFinished() " &lt;&lt; reply-&gt;isFinished();
        emit DownloadFinished(QNetworkReply::TimeoutError);
        emit StatusUpdate("the connection to the remote server timed out");
    }
}
reply-&gt;deleteLater();
reply = NULL;
</code></pre>
<p dir="auto">}</p>
<p dir="auto">void Ftp::downloadinProgress(qint64 bytesReceived, qint64 bytesTotal)<br />
{<br />
#if DEBUG_LEVEL_FTP &gt; LOG_ERRORS<br />
qDebug() &lt;&lt; this-&gt;metaObject()-&gt;className() &lt;&lt; "downloadinProgress " &lt;&lt; "bytesReceived " &lt;&lt; bytesReceived &lt;&lt; "bytesTotal " &lt;&lt; bytesTotal;<br />
#endif</p>
<pre><code>connecttimer.start();
</code></pre>
<p dir="auto">}</p>
<p dir="auto">void Ftp::slotReadyRead(void)<br />
{<br />
#if DEBUG_LEVEL_FTP &gt; LOG_ERRORS<br />
qDebug() &lt;&lt; this-&gt;metaObject()-&gt;className() &lt;&lt; "slotReadyRead";<br />
#endif</p>
<pre><code>connecttimer.start();
</code></pre>
<p dir="auto">}</p>
<p dir="auto">void Ftp::replyfinished()<br />
{<br />
connecttimer.stop();</p>
<pre><code>#if DEBUG_LEVEL_FTP &gt; LOG_ERRORS
     qDebug() &lt;&lt; this-&gt;metaObject()-&gt;className() &lt;&lt;"replyfinished ";
#endif
if(reply)
{
    #if DEBUG_LEVEL_FTP &gt; LOG_ERRORS
        qDebug() &lt;&lt; this-&gt;metaObject()-&gt;className() &lt;&lt; "if reply ";
    #endif
    if(reply-&gt;bytesAvailable())
    {
        QFile file&amp;#40;QApplication::applicationDirPath(&amp;#41; +"/" + cf.GetProgramName() + TEMP_FILENAME_EXT);
        file.open(QIODevice::WriteOnly);

        #if DEBUG_LEVEL_FTP &gt; LOG_ERRORS
             qDebug() &lt;&lt; this-&gt;metaObject()-&gt;className() &lt;&lt; "file write: " &lt;&lt; file.write(reply-&gt;readAll());
        #endif

        file.close();
    }
    emit DownloadFinished(reply-&gt;error());
    qDebug() &lt;&lt; reply-&gt;errorString()&lt;&lt; " reply-&gt;error() " &lt;&lt; reply-&gt;error();
    if(reply-&gt;error() == 0)
        emit StatusUpdate("No error");
    else
        emit StatusUpdate(reply-&gt;errorString());
}
else
{
    emit DownloadFinished(QNetworkReply::TimeoutError);
    emit StatusUpdate("the connection to the remote server timed out");
}
reply-&gt;deleteLater();
reply = NULL;
</code></pre>
<p dir="auto">}</p>
<p dir="auto">void Ftp::slotError(QNetworkReply::NetworkError error)<br />
{</p>
<pre><code>#if DEBUG_LEVEL_FTP &gt; LOG_NOTHING
     qDebug() &lt;&lt; this-&gt;metaObject()-&gt;className() &lt;&lt;"slotError: " &lt;&lt; error;
#endif

if(error)
{
    connecttimer.stop();
    emit DownloadFinished(reply-&gt;error());
    emit StatusUpdate(reply-&gt;errorString());
    reply-&gt;deleteLater();
    reply = NULL;
}
</code></pre>
<p dir="auto">}</p>
<p dir="auto">@</p>
]]></description><link>https://forum.qt.io/topic/24534/simple-ftp-file-transfer-reconnect-problem</link><generator>RSS for Node</generator><lastBuildDate>Sat, 11 Apr 2026 01:00:17 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/24534.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 22 Feb 2013 16:21:57 GMT</pubDate><ttl>60</ttl></channel></rss>