Upload file with QAccessManager - problem with url
-
Hi, I got problem with typing good url address to upload file to my server. This is my whole code:
@void FttpClient::ConnectWithServer()
{
// create file
QString filename="/home/vla/Documents/Data.txt";
QFile file( filename );
if ( file.open(QIODevice::ReadWrite) )
{
QTextStream stream( &file );
stream << "I write somethign hjeer e" << endl;
}// handle connection manager = new QNetworkAccessManager(this); connect(manager, SIGNAL(finished(QNetworkReply*)),this, SLOT(replyFinished(QNetworkReply*))); url.setUrl("ftp://blalala.bugs3.com/"); qDebug("set url "); url.setUserName("userName"); qDebug("set user name "); url.setPassword("pw"); qDebug("set pw "); url.setPort(21); qDebug("set port"); manager->put(QNetworkRequest(url),&file); qDebug("put method from manager"); file.close(); qDebug("file closed");
}
// and the last method when I get reply for posting
// action
void FttpClient::replyFinished (QNetworkReply *reply)
{
qDebug("reply getted");
if(reply->error())
{
qDebug() << "ERROR!";
qDebug() << reply->errorString();
qDebug() << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
qDebug() << reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString();
}
else
{
qDebug() << reply->header(QNetworkRequest::ContentTypeHeader).toString();
qDebug() << reply->header(QNetworkRequest::LastModifiedHeader).toDateTime().toString();;
qDebug() << reply->header(QNetworkRequest::ContentLengthHeader).toULongLong();
qDebug() << reply->header(QNetworkRequest::CookieHeader).toString();
qDebug() << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
qDebug() << reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString();} reply->deleteLater();
}@
when address look like in the code above, output which I got says me :
" Cannot open ftp://userName:pw@blalala.bugs3.com:21/: is a directory"
and the userName is the values set here:
@ url.setUserName("userName");@
the same with pw.When I try to add in url some directory like this
@url.setUrl("ftp://blalala.bugs3.com/mydire")@bq. the output looks like this
set url
set user name
set pw
set port
put method from manager
file closed
The program has unexpectedly finished.so I don't get any info, even response isn't invoked. I tried to set some file in url which should be created, but the result is the same as with adding directory to url so the app finishing unexpected...
What is the problem here ?
I would be grateful for any advices. If u need more details just give me a word.
EDIT the url(ftp://blalala.bugs3.com/), user name and pw which I', using inside the code was tested with filezilla, so it's impossible that I putting wrong credential.