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. QT5 QNetworkAccessManager does not put File on FTP Server

QT5 QNetworkAccessManager does not put File on FTP Server

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 9.3k 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.
  • V Offline
    V Offline
    vod1
    wrote on last edited by
    #1

    After googling now for a while i still have no clue, why the Code does not work.
    I tried much of the things suggested in forums, but still its not working.

    The problem is, that the QNAM never calls the uploadFinished-Slot. There is no Error too, the Error Slot is also not triggered. There is no Problem opening the file..
    The uploadProgress Slot is not called too.

    As far as i can say, there is a valid QNetworkReply when i call the put function.

    I dont know, its just doing nothing.

    Has anybody a good idea what the problem could be?

    @MainWindow::MainWindow(QWidget parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    connect(&manager, SIGNAL(finished(QNetworkReply
    )), SLOT(uploadFinished(QNetworkReply*)));
    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    void MainWindow::doUpload(const QString &file)
    {
    QUrl url("ftp://server/files/jgevas_FTPTest.txt");
    url.setUserName("login");
    url.setPassword("password");
    url.setPort(25);

    data = new QFile(file, this);

    if (data->open(QIODevice::ReadOnly)) {
    reply = manager.put(QNetworkRequest(url), data);

    connect(reply, SIGNAL(uploadProgress(qint64, qint64)), SLOT(uploadProgress(qint64, qint64)));
    

    }
    else
    qDebug() << "Problem";
    }

    void MainWindow::uploadFinished(QNetworkReply *reply)
    {
    qDebug() << "Finished" << reply->error();

    data->deleteLater();
    reply->deleteLater();
    }

    void MainWindow::execute()
    {
    doUpload("data/New Text Document.txt");
    }

    void MainWindow::uploadProgress(qint64 bytesSent, qint64 bytesTotal) {
    qDebug() << "Uploaded " << bytesSent << "of " << bytesTotal;
    }
    @

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vod1
      wrote on last edited by
      #2

      Found the Bug myself... took a long time!
      I can not explain why, but when i uncomment the setPort() statement it works...

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Schnizel1337
        wrote on last edited by
        #3

        Sorry for the really late answer,
        but this is obvious:

        you cannot upload an file to ftp on port 25
        because setPort sets the post to connect on
        and not on which port the data should be sent from your computer

        the ftp upload port is 21 not 25
        so just replace the setPort line with:

        @url.setPort(21);@

        1 Reply Last reply
        0
        • 独 Offline
          独 Offline
          独行黑鹰
          wrote on last edited by
          #4

          I always get the error that "QIODevice: : read: device not open", when you use the Qt 5.3 .I don't the reason.

          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