Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. ftp upload fails
Forum Updated to NodeBB v4.3 + New Features

ftp upload fails

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    janbur
    wrote on last edited by janbur
    #1

    On Qt 5.7.0 win10 UWP winrt x86 version I get the messages below when trying to upload a file on my ftp server:

    qt.winrtrunner.app: Could not obtain NoDelay information from socket control
    qt.winrtrunner.app: Uploaded 126 of 126

    The result is the creation of an empty file with 0 bytes, the finished slot never fires.
    It helps when I copy
    data->deleteLater();
    reply->deleteLater();
    to the uploadProgress slot, 1 in 2 attempts succeed then with the creation of a 126 bytes file.

    But this is not good enough of course, anyone any idea why the finished Signal never fires ?

    class Uploader: public QObject
    {
        Q_OBJECT
    public:
        Uploader(QObject *p = 0): QObject(p)     {  }
    
        void start(const QString &file)     {
            QUrl url("ftp://ftp.xxxxxx.com/test.txt");
            url.setUserName("ftp_xxxx@yyyyy.com");
            url.setPassword("xxxxxx");
            url.setPort(21);
    
            data = new QFile(file, this);
            if (data->open(QIODevice::ReadOnly)) {
                reply = nam.put(QNetworkRequest(url), data);
                connect(reply, SIGNAL(uploadProgress(qint64, qint64)), SLOT(uploadProgress(qint64, qint64)));
                connect(reply, SIGNAL(finished()), SLOT(uploadDone()));
            }
            else
                qDebug() << "Oops";
        }
    
    public slots:
        void uploadProgress(qint64 bytesSent, qint64 bytesTotal)    {
            qDebug() << "Uploaded" << bytesSent << "of" << bytesTotal;
        }
    
        void uploadDone()     {
            qDebug() << "Finished" << reply->error();
            data->deleteLater();
            reply->deleteLater();
        }
    
    private:
        QNetworkAccessManager nam;
        QFile *data;
        QNetworkReply *reply;
    };
    
    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      2 things:

      • can you show us the snippet where you call start?
      • can you connect QNetworkReply::error signal to a slot to debug what is happening?

      one minor thing is make the two slots private as calling uploadDone() before calling start will operate on a dangling data pointer

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      0
      • J Offline
        J Offline
        janbur
        wrote on last edited by janbur
        #3

        I'm using the widgets/mainwindows/application example.

        I've tried the Error signal + slot, but it didn't execute (like the finished slot).

        In mainwindow.h I added the uploader object and in class MainWindow:

        private:
            QString filenameup;
            QFile fileup;
            Uploader u3;
        

        In mainwindow.cpp I added in bool MainWindow::save() :
        (pressing the Save button of the app's menu starts the upload)

            str1 = str1.left(126);
        
            QByteArray qbarr;
            qbarr.clear();
            qbarr.append(str1);
        
            QString path = QStandardPaths::standardLocations(QStandardPaths::AppDataLocation).value(0);
            filenameup = path + "\\test.txt";
            fileup.close();
            fileup.setFileName(filenameup);
            fileup.open(QIODevice::ReadWrite);
            fileup.write(qbarr);
            fileup.close();
        
            u3.start(filenameup);
        
            QTime t; 
            t.start();
            while(t.elapsed() < 3000) {
               QCoreApplication::processEvents(QEventLoop::AllEvents, 3000-t.elapsed());
            }
        
            fileup.close();
        
            return 0;
        }
        
        1 Reply Last reply
        0
        • J Offline
          J Offline
          janbur
          wrote on last edited by
          #4

          Today I compiled this piece of coding with Qt 5.3 for Windows on a Windows 10 machine.
          And it runs like a charm, it executes the Finished slot and does the ftp upload.

          So it looks like it has sth to do with Qt 5.7 and winrt/uwp

          Note: Qt 5.3 doesn't know QStandardPaths::standardLocations(QStandardPaths::AppDataLocation).value(0);
          changed this to:
          filenameup = "test.txt";

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved