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 access with Qt 5.3
Forum Update on Monday, May 27th 2025

FTP access with Qt 5.3

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 2.0k Views
  • 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.
  • K Offline
    K Offline
    kloveridge
    wrote on last edited by
    #1

    Okay, I've tried to avoid asking this question but I simply cannot wrap my head around how to work with a ftp site and use QNetworkAccessManager. Qt's documentation explains how to use the classes is pieces. But doesn't have a good example that shows how to use them together.

    Part of the confusion lies in the fact that apparently in Qt 5 they no longer support QFtp--or at least discourage us from using it. But every example I can find uses QFtp!

    So my basic starting point is, I wanted to log into my ftp site and just get a list of files from a given directory, how is this done with QNetworkAccessManager? Here's what I've done so far. But clearly, this isn't executing a pwd command. Not sure where that even occurs...

    // Header
    @#ifndef NETWORKMANAGER_H
    #define NETWORKMANAGER_H

    #include <QObject>
    #include <QNetworkAccessManager>

    class QNetworkReply;
    class QNetworkAccessManager;
    class NetworkManager : public QObject
    {
    Q_OBJECT
    private:
    QNetworkAccessManager m_netman;

    public:
    explicit NetworkManager(QObject *parent = 0);
    ~NetworkManager();

    bool ftpTester();

    signals:

    public slots:
    void replyFinished(QNetworkReply *_reply);

    };

    #endif // NETWORKMANAGER_H
    @

    // Cpp
    @#include "NetworkManager.h"
    #include <QNetworkRequest>
    #include <QNetworkReply>
    #include <QUrl>
    #include <Underworld/Base/NStatus.h>

    NetworkManager::NetworkManager(QObject parent) :
    QObject(parent)
    {
    connect(&m_netman, SIGNAL(finished(QNetworkReply
    )),
    this, SLOT(replyFinished(QNetworkReply*)));
    }

    NetworkManager::~NetworkManager()
    {
    }

    bool NetworkManager::ftpTester()
    {
    QNetworkRequest request(QUrl("ftp://<username>:<password>@ftp.mysite.com/sweetFTP/"));
    m_netman.get(request);
    return false;
    }

    void NetworkManager::replyFinished(QNetworkReply *_reply)
    {
    if( _reply->error())
    {
    NStatus::nowError("Unable to get to ftp site.");
    NStatus::nowError(_reply->errorString());
    } else {
    NStatus::nowNote(_reply->header(QNetworkRequest::ContentTypeHeader).toString());
    }
    _reply->deleteLater();
    }@

    any direction, tutorials I can read or any code samples would be appreciated!

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      For the time being you can only use put() and get() when accessing ftp with QNetworkAccessManager ie. upload or download a file assuming you know the path beforehand. To use commands like "PWD" or "LIST" you would have to go a level down, to a QTcpSocket I suppose.

      1 Reply Last reply
      0
      • K Offline
        K Offline
        koahnig
        wrote on last edited by
        #3

        There is also "QtFtp":https://qt.gitorious.org/qt/qtftp/source/80823b53d2025d9c0c15075c325ee0c2e364551b: which is referred "here":http://qt-project.org/forums/viewthread/24466
        You can see in the example how to use QNetworkAccessManager as QFtp used to be. Alternatively, you can use the easy route and use the compatibility class directly.

        Vote the answer(s) that helped you to solve your issue(s)

        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