PDA

View Full Version : ftp file upload



mouni
29th August 2016, 18:00
Hi freinds,


i want some example code for ftp upload in qt5.3.

can any one help.

d_stranz
30th August 2016, 01:26
can any one help.
Google can. (http://lmgtfy.com/?q=example+code+for+ftp+upload+in+qt)

I guess you find it easier to use this forum as your search engine.

pradeepreddyg95
4th September 2016, 01:46
check QFtp ...

mouni
6th September 2016, 13:31
QFtp is not working in Qt5.3...

in which process can i use

anda_skoa
6th September 2016, 14:45
You could try a QNetworkAccessManager::put() operation with an ftp URL.

Cheers,
_

mouni
6th September 2016, 16:06
QNetworkAccessManager *Ftp = new QNetworkAccessManager(this);
QNetworkReply *reply = new QNetworkReply (this);
QUrl url ("ftp://192.168.192.91/test.txt");
url.setUserName(test);
url.setPassword(test);
url.setPort(21);


QFile *data = new QFile(test.txt);

if(!data->open(QIODevice::ReadOnly))
{
qDebug() << "Could not open file to FTP";
QMessageBox::information(this,"FTP ","Could not open file to FTP");
return false;

}
else
{
reply = Ftp->put(QNetworkRequest(url),data);
}




but i getting error like this

QIODevice::read: device not open
Error Code: "Unknown error"


can anybody tell why it is coming and give some solution....

anda_skoa
6th September 2016, 17:03
QNetworkReply *reply = new QNetworkReply (this);


Any specifc reason why you create a QNetworkReply object here?





QUrl url ("ftp://192.168.192.91/test.txt");


Is that a writable location on the target server?



but i getting error like this

QIODevice::read: device not open
Error Code: "Unknown error"

When do you get this?

Cheers,
_

mouni
7th September 2016, 06:58
no

it is a writable location on server


while uploading file error is coming

anda_skoa
7th September 2016, 11:22
it is a writable location on server

Ok.



while uploading file error is coming
So you have connected to the QNetworkReply::error() signal and it is emitted before finished()?

Where do you close/delete the "data" object? In the slot for QNetworkReply::finished()?

Maybe try "post" instead of "put".

Cheers,
_

mouni
8th September 2016, 09:17
it is showing QIODevice::read: device not open

but files uploading to server...

what is problem i am not understanding

anda_skoa
8th September 2016, 11:26
Are you maybe calling "read" or "readAll" on the reply object?

Cheers,
_

mouni
8th September 2016, 16:01
i am not calling read or readall


when file is given QIODevice::readonly i given..

QFile *data = new QFile(test.txt);

if(!data->open(QIODevice::ReadOnly))
{
qDebug() << "Could not open file to FTP";
QMessageBox::information(this,"FTP ","Could not open file to FTP");
return ;
}
reply = Ftp->put(QNetworkRequest(url),data);

where data is QFile

reply is qnetworkreply

ftp is qnetworkacessmanager...