3

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.

Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778

1 Answers1

2

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.

Orest Hera
  • 6,706
  • 2
  • 21
  • 35
  • What happens when you call get or put when connected to hhtp aerver? – Tomáš Zato Sep 14 '15 at 16:33
  • @TomášZato If the request URL is started from "http://" the function `get()` works as expected for HTTP protocol. If the URL is started by "ftp://", `get()` will download the required file using FTP protocol. – Orest Hera Sep 14 '15 at 16:59
  • @TomášZato In case of FTP, `QNetworkReply` instance also emits signal `metaDataChanged()` once the connection is established. So, it is possible to check file size and date using "Content-Length" and "Last-Modified" header fields (`rawHeaderPairs()`). – Orest Hera Sep 14 '15 at 17:08