3

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.

Kevin Panko
  • 8,356
  • 19
  • 50
  • 61
user2584587
  • 133
  • 2
  • 10

2 Answers2

2

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

skytaker
  • 4,159
  • 1
  • 21
  • 31
Santi
  • 29
  • 4
  • 2
    What when the link goes dead? Please when you have time, try to *at least* copy the explanation here. Best would be if you'd taken time to extend it. It actually took me a while and I didn't find the explanation. – Tomáš Zato Sep 14 '15 at 13:39
  • @Tomáš Zato There is an example in the link, and this is too much long to copy here. You only need copy the code on the question and replace parts I mentioned. – Santi Dec 04 '15 at 16:18
1

Try file.flush(); after write.

masoud
  • 55,379
  • 16
  • 141
  • 208
kvv
  • 336
  • 1
  • 13
  • Hmm, well may be you should seek to the beginning of the file before you send contents. Trying my luck last time:) – kvv Jul 19 '13 at 21:30
  • Doesn't `file.close();` run a flush? I think it does. – masoud Nov 18 '13 at 09:02
  • 1
    @M M., file.close(); runs flush indeed! Reimplemented from QIODevice::close(). Calls QFile::flush() and closes the file. Errors from flush are ignored. – kvv Dec 17 '13 at 13:46