FTP transfer error AuthenticationRequiredError although user and password are set
-
Hello all
I try to upload a file to a directory via ftp, which has worked some time ago.
I dont know what has changed, but I have the strange error Message "QNetworkReply::AuthenticationRequiredError" although I have set user and password.void MainWindow::on_btn_upload_file_clicked(){ QNetworkAccessManager *NetworkAccessManager = new QNetworkAccessManager(); QString zielname = "C:/Users/tomax/Desktop/test.pdf"; QString filepath = "ftp://server.de:21/homepath/public_html/docs/test.pdf"; QFile *QuellFile = new QFile(C:/Users/tomax/Desktop/test.pdf); QUrl url; url.setScheme("ftp"); url.setHost("server.de"); //FTP server oder domain url.setPath("zielserver.de/public_html/docs/test.pdf"); // hier Zielname einfügen url.setUserName("username"); url.setPassword("passwort"); url.setPort(21); qDebug() << url.userName(); qDebug() << url.password(); QNetworkRequest request(url); if(QuellFile->open(QIODevice::ReadWrite)){ QNetworkReply *reply = NetworkAccessManager->put(request, QuellFile); connect(reply, &QNetworkReply::uploadProgress, this, &MainWindow::uploadProgress); connect(reply, SIGNAL(uploadProgress(qint64, qint64)), this, SLOT(uploadProgress(qint64,qint64))); connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(loadError(QNetworkReply::NetworkError))); } }
qDebug() << url.userName(); and qDebug() << url.password();
give the correct username and password.
Any idea?
-
@Thomas-63 Please copy and paste from your actual, compiling code. The fifth line of your snippet will not compile.
When you say that the debug output, "give the correct username and password," I assume you mean the value you expected to see. QNetworkReply::AuthenticationRequiredError means, "the remote server requires authentication to serve the content but the credentials provided were not accepted (if any)." So, either the credentials are not being received at the other end or they are incorrect.
The credentials in your code snippet are clearly not the real ones, so it's not possible for us to independently check.
-