QNetworkAccessManager upload to local FTP server

女生的网名这么多〃 提交于 2019-12-22 12:23:58

问题


I can download from the server but I can't upload to it. It uploads the file but it's an empty file.

This is basically what I'm doing:

QString filename="Data.txt";
QFile file( filename );
file.open(QIODevice::ReadWrite);
file.write("HELLO") ;

QUrl urlup("ftp://127.0.0.1/file.txt");
urlup.setPassword("123");
urlup.setUserName("user");
urlup.setPort(21);
QNetworkAccessManager *nam = new QNetworkAccessManager;
QNetworkRequest requp(urlup);
nam->put(requp,&file);
file.close();

but it's not working; just uploads an empty file.


回答1:


Instead of 127.0.0.1 use localhost

Instead of setPort append :PortNumber to url. (For example ftp://localhost:21)

Answer in this link: Putting large size file on FTP using QNetworkAccessManager




回答2:


Try file.flush(); after write.



来源:https://stackoverflow.com/questions/17755498/qnetworkaccessmanager-upload-to-local-ftp-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!