0

I have a problem which is quite similar to my last question Ssh command from Qt. But I cannot understand what is wrong with one of the arguments that I pass to cUrl in QProcess. The code is:

  QStringList params;
  const double timeout = 8.0;
  params.append("'--connect-timeout " + QString("%1").arg(timeout) + "'");
  params.append("-T" + obj->absoluteFilePath());
  params.append("ftp://" + m_host + "/inbox" + m_logsPath + obj->name());
  m_process->start("curl", params);

But it always gives me an error: curl: option --connect-timeout 8: is unknown. And again when I run it from the command line everything is fine. I understand that I have an error while passing argumnets, but I can't find it. Thanx a lot!

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Polina Bodnar
  • 171
  • 3
  • 15
  • It should be `params.append(QString("--connect-timeout %1").arg(timeout) );` instead, I believe. – vahancho Feb 27 '18 at 16:46
  • 1
    Why not use `QNetworkAccessManager` for this? It's built into Qt and includes FTP support. – MrEricSir Feb 27 '18 at 16:57
  • @MrEricSir Yes, thanx for your notice. I wanted to use it. But I need do upload, download and delete files from ftp server. And when I serached through the net the only option that I found about deleting files was using cUrl from QProcess. – Polina Bodnar Feb 27 '18 at 18:00

1 Answers1

1

Try:

  QStringList params;
  const double timeout = 8.0;
  params.append("--connect-timeout");
  params.append(QString("%1").arg(timeout));
  params.append("-T" + obj->absoluteFilePath());
  params.append("ftp://" + m_host + "/inbox" + m_logsPath + obj->name());
  m_process->start("curl", params);

With your version you are passing something like

curl "'--connect-timeout <timeout>'" #curl sees 1 arg

With mine it is:

curl "--connect-timeout" "<timeout>" #curl sees 2 arg, as it is generally the case when executing it from a shell

Keep in mind that start() will not split each params element further.

Benjamin T
  • 8,120
  • 20
  • 37
  • Thanx so much for your answer! But it didn't help. The error is still the same. – Polina Bodnar Feb 27 '18 at 17:57
  • Wow. I was very mistaken. When I used your example I forgot to remove the space at the end of "--connect-timeout " in my code. So after removing it it works fine. Thanx a lot! – Polina Bodnar Feb 28 '18 at 08:24