如何使用 Qt/QNetworkAccessManager 实现 SFTP (C++)
我是 Qt 新手,我想为我的软件实现 FTP 和 SFTP 支持。 当我用谷歌搜索时,我发现 Qt 不存在 sftp 库,但使用 QNetworkAccessManager 应该可以。 然后我试图发现如何构建自定义协议或类似的东西,但不知道如何去做。
有人知道我该怎么做吗?
谢谢, 迈克尔
I'm new to Qt and I would like to implement FTP and SFTP support for my software.
As I googled I discovered that there doesn't exist a sftp library for Qt but it should be possible with QNetworkAccessManager.
I tried then to discover on how to build a custom protocol or something like that but didn't figure out how to do it.
Does someone know how I could do that?
Thanks,
Michael
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Qt SDK 中不支持 SFTP,但 Qt Creator 实现了 SFTP。
我已经隔离了包含 SSH 和 SFTP 的库,并在 Github 中创建了一个名为 QSsh 的新项目。该项目的目标是为任何 Qt 应用程序提供 SSH 和 SFTP 支持。
我写了一个关于如何使用 SFTP 上传文件的示例。看看
examples/SecureUploader/
我希望它可能会有所帮助
There is no support for SFTP in Qt SDK but Qt Creator implements SFTP.
I have isolated the library that contains SSH and SFTP and I have created a new project named QSsh in Github. The aim of the project is to provide SSH and SFTP support for any Qt Application.
I have written an example on how to upload a file using SFTP. Take a look at
examples/SecureUploader/
I hope it might be helpful
您需要为每个协议定制实现。但我们可以创建一个像 QHttp 这样的类来做到这一点。有几个协议具有相似的语义,但不是全部。所以,如果你想写,请告诉我,我会帮助你。
You need a custom implementation for each protocol. But we can create a class like QHttp which will do that. There are several protocols that has similar semantic, but not all. So, if you want write it, tell me and I help you.
Qt SDK 中当前没有 SSH 包装器实现。您在这里有 3 个选择:
There's no current SSH wrapper implementation in the Qt SDK. You have 3 choices here:
我使用 libssh 来完成此操作。非常直接。
https://api.libssh.org/stable/libssh_tutor_sftp.html
不要忘记将 sftp 服务器添加到系统中的已知主机中。
示例代码:
I do this using libssh. Very straight forward.
https://api.libssh.org/stable/libssh_tutor_sftp.html
Don't forget to add your sftp server into known hosts in your system.
Example code: