问题
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