尝试使用Qt通过FTP上传文件时发生错误 [英] Error occuring when trying to upload file via FTP using Qt

查看:1018
本文介绍了尝试使用Qt通过FTP上传文件时发生错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的文件夹中有一个文件,我想通过FTP将它发送到我的嵌入式Linux设备(很像这个这个)。我知道一步一步做到这一点,但是在创建正确的QUrl时我失败了:当我调用''put''时,我总是得到错误301:


QNetworkReply :: ProtocolUnknownError 301网络访问API无法兑现请求,因为协议未知


作为细节,我想将文件保存在设备中的SD卡内的特定目录中, / media / mmcblk0p2 / bin ,并且连接至少现在没有定义的密码和用户名¹。另外有趣的是,我不能通过使用终端的FTP连接我自己;它总是说421服务不可用,远程服务器已关闭连接,这与AFAIK不是同一个问题。 (顺便说一下,我可以使用FileZilla通过SSH连接,所以它不是硬件/物理问题)。

那么问题在哪里?我的代码与上述链接完全相同。至于现在,我使用的链接是

  ftp://10.1.25.10/media/mmcblk0p2/bin/center .png 

(当用QDebug返回QUrl对象时),我无法做到这一点工作。



任何帮助将不胜感激。

¹:顺便说一句,我记得在某个地方,当一个用户不使用用户名连接到FTP时,系统只允许客户端连接到/ ftp文件夹。真的吗?在这种情况下,只需调用 QUrl :: setUserName(root); 就足够了吗?

解决方案

我终于发现我的问题了:因为我是从上传到HTTP服务器的例子中复制代码的,所以我使用了专用于HTTP的函数post,而不是put,这是正确的函数



关于QUrl,我使用了 QUrl urlTemp(// 10.1.25.10/test.info\");,同时告诉它使用ftp, urlTemp.setScheme(ftp);


I have a file in my folder and I want to send it to my Embedded Linux device via FTP (much like this and this and this). I know the step-by-step to do it, but I'm failing when it comes to creating the correct QUrl for it: when I call ''put'', I always get the error 301:

QNetworkReply::ProtocolUnknownError 301 the Network Access API cannot honor the request because the protocol is not known

As details, I want to save the file in a specific directory located inside a SD Card in the device, /media/mmcblk0p2/bin, and the connection doesn't have, at least for now, a password and user name defined¹. Also interesting to notice that I'm not being able to connect myself via FTP using Terminal; it always says "421 Service not available, remote server has closed connection", which is not the same problem AFAIK. (Btw I'm being able to connect via SSH using FileZilla, so it's not a hardware/physical problem)

So where is the problem? I have exactly the same code as in the mentioned links. As for now, the link I'm using is

ftp://10.1.25.10/media/mmcblk0p2/bin/center.png

(when returning the QUrl object with QDebug) and I'm not being able to make it work.

Any help would be appreciated.

¹: Btw I remember reading somewhere that when one doesn't use a user name for connecting to FTP, the system only allows the client to connect to the /ftp folder. Is that true? In that case, just calling QUrl::setUserName("root"); would suffice?

解决方案

I finally discovered my problem: since I was copying the code from examples of upload to HTTP servers, I was using the function "post", specific for HTTP, instead of "put" which was the correct function to use.

Regarding the QUrl, I used QUrl urlTemp("//10.1.25.10/test.info"); while telling it to use ftp with scheme, urlTemp.setScheme("ftp");.

这篇关于尝试使用Qt通过FTP上传文件时发生错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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