Tomáš Zato
Tomáš Zato

Reputation: 53119

How is FTP supposed to work with QNetworkAccessManager?

So QFtp was removed because it had bad design they say. Whatever.

However, for new applications, it is recommended to use QNetworkAccessManager and QNetworkReply, as those classes possess a simpler, yet more powerful API. (from docs)

I looked up QNetworkAccessManager and it's just confusing. It's not socket and doesn't even seem to provide raw socket methods. But it's also not FTP. It provides HTTP related functions like cookieJar, post, get... Can someone remind me how does FTP respond to HTTP data?

So this question consists of two parts:

  1. What are we basically expected to do to do a simple connection to FTP server and one basic operation, like dir listing.
  2. How does it work on low-level, and why.

I have of course found some code and I'm now trying to get it to work, but the real problem is that it makes no sense to me.

Upvotes: 3

Views: 5512

Answers (1)

Orest Hera
Orest Hera

Reputation: 6776

Current FTP back-end of QNetworkAccessManager implements get() and put() operations. So, it should be enough to download or to upload files using FTP protocol.

The protocol used by QNetworkAccessManager is defined by URL scheme. So, for FTP URLs ("ftp://..."), the functions get() or put() create connection using FTP protocol.

Username and password are taken from QUrl::userName() and QUrl::password().

So, the key words in the docs are "a simpler API". It is not needed to execute manually connect, login, cd and get commands. Thus, it is not needed to implement own state machine to manage many FTP states in asynchronous application as it was before with QFtp

QNetworkAccessManager provides much simpler API for downloading/uploading files.

For other FTP commands some external module should be used like Qt Ftp.

Upvotes: 2

Related Questions