0

I have some issue in passing a FTP string into QUrl:

std::cout << QUrl::fromUserInput("ftp://user@host.com:password@ftphost:21/path/file.ext").toString().toStdString().c_str() << std::endl;

Is always resulting in

http://ftp//user@host.com:password@ftphost:21/path/file.ext

which is obviously wrong. What's the problem with the above FTP Url? Or is that a known issue within Qt4?

I am working on Linux, using Qt 4.8.1.

Even following code

if(QUrl("ftp://user@host.com:password@ftphost:21/path/file.ext").isValid())
    std::cout << "is valid" << std::endl;
else
    std::cout << "is not valid" << std::endl;

Is resulting in "is not valid"

Thanks in advance

Motti
  • 110,860
  • 49
  • 189
  • 262
sarahara
  • 65
  • 6

1 Answers1

1

You need manually replace @ in username with %40. That's what QUrl does internally if QUrl::setUserName() is called with user@domain.tld.

Oleg Shparber
  • 2,732
  • 1
  • 18
  • 19
  • Thanks Oleg for the hint! I was able to fix the issue with your help, however, using Qt4, authentication will fail because of the %40. I am just doing a hack to get that resolved: `finalUrl.setUserName(QUrl::fromEncoded(finalUrl.userName().toLatin1()).toString());` With passing `%40` to QUrl and this small correction, everything works fine. Even on Qt4. Thanks again – sarahara Jul 25 '14 at 07:36