Error occuring when trying to upload file via FTP

2019-09-07 01:27发布

问题:

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?

回答1:

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 upload ftp