FTP应该如何与QNetworkAccessManager一起使用? [英] How is FTP supposed to work with QNetworkAccessManager?

查看:130
本文介绍了FTP应该如何与QNetworkAccessManager一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此, QFtp 被删除,因为它的设计错误。随你。不过,对于新的应用程序,建议使用
QNetworkAccessManager和QNetworkReply,因为这些类拥有
更简单但功能更强大的API。 (来自 文档


我查找了 QNetworkAccessManager ,这只是令人困惑。它不是套接字,甚至不提供原始套接字方法。但它也不是FTP。它提供了HTTP相关的功能,比如 cookieJar post get ...有人可以提醒我FTP如何响应HTTP数据?



所以这个问题包含两部分:


  1. 我们基本上期望做什么来做一个简单的FTP服务器连接和一个基本的操作,比如dir列表。

  2. 它是如何工作的低级别,以及为什么。

我当然发现了一些代码,现在我试图让它工作,但真正的问题在于它对我来说没有意义。

解决方案

当前FTP后端 QNetworkAccessManager 执行 get() put()操作。因此,它应该足以下载或使用FTP协议上传文件。


$ b $ < QNetworkAccessManager 使用的协议是由 URL scheme 定义。
因此,对于FTP URL(ftp:// ...),函数 get() put()使用FTP协议创建连接。



用户名和密码取自 QUrl :: userName() QUrl :: password()



所以,文档中的关键词是 更简单的API。不需要手动执行 connect login cd 获取命令。因此,不需要像以前一样使用 QFtp

QNetworkAccessManager 为下载/上传文件提供了更简单的API。



对于其他FTP命令,应该使用一些外部模块,如 Qt Ftp


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.

解决方案

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.

这篇关于FTP应该如何与QNetworkAccessManager一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆