Problem Using QNetworkAccessManager ftp (SOLVED)
-
@QFile *fichero=new QFile("C://a/prueba.txt",this);
if (fichero->open(QIODevice::ReadWrite)){QUrl direccion("ftp://pi:raspberry@192.168.1.130/home/pi/proyecto/prueba.txt"); QNetworkAccessManager *nman=new QNetworkAccessManager(); connect(nman,SIGNAL(finished(QNetworkReply*)),this,SLOT(terminareq(QNetworkReply*))); QNetworkRequest req; req.setUrl(direccion); nman->put(req,fichero); fichero->close(); }@
When I put the file i only have a empty file in my server. What's the problem here??? I'm so worried with this!!!!
PD: when i capture de qnetworkreply data is an Unknow error
-
There are the compatibility "addons with QtFtp.":https://qt.gitorious.org/qt/qtftp In there you can see, how to do an ftp transfer.
-
I have just solved!!!! The problem is that fichero must be open while the writing is running until the signal finished is emited.
@void QHorarioCompleto::pulsaenviar()
{
fichero=new QFile("C://a/prueba.txt",this);
if (fichero->open(QIODevice::ReadWrite)){QUrl direccion("ftp://pi:raspberry@192.168.1.130/home/pi/proyecto/prueba.txt"); QNetworkAccessManager *nman=new QNetworkAccessManager(); connect(nman,SIGNAL(finished(QNetworkReply*)),this,SLOT(terminareq(QNetworkReply*))); QNetworkRequest req; req.setUrl(direccion); nman->put(req,fichero); }
}
void QHorarioCompleto::terminareq(QNetworkReply *respuesta)
{
fichero->close();
qDebug() << "Finished ";
qDebug()<<respuesta->errorString();
}@
This works really good!!! Share it!!!