1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
void BiblioBD::RetrieveWebData()
{
mftp = new QFtp(this);
connect(mftp, SIGNAL(commandFinished(int,bool)),
this, SLOT(ftpCommandFinished(int,bool)));
connect(mftp, SIGNAL(readyRead()), this, SLOT(readyRead()));
//je récupère l'adresse comprse dans le champs 'adresse du serveur FTP'
QString host = "ftpperso.free.fr";
//je me connecte au serveur FTP...
mftp->connectToHost(host,21);
//...qui demande les login/password contenus dans les champs prévus à cet effet
mftp->login("bibliobd","xxxxx");
mfichierWeb = new QFile("bibliobdWeb.csv");
mfichierWeb->open(QIODevice::WriteOnly);
mftp->get("bibliobdWeb.csv",mfichierWeb);
}
void BiblioBD::readyRead(){
mfichierWeb->write(mftp->readAll());
}
void BiblioBD::ftpCommandFinished(int, bool error)
{
#ifndef QT_NO_CURSOR
setCursor(Qt::ArrowCursor);
#endif
if (mftp->currentCommand() == QFtp::ConnectToHost) {
if (error) {
QMessageBox::information(this, tr("BiblioBD"),
tr("Unable to connect to the FTP server "
"Please check that the host "
"name is correct.")
);
return;
}
return;
}if (mftp->currentCommand() == QFtp::Get) {
if (error) {
QMessageBox::information(this, tr("BiblioBD"),
tr("Problème de transfert"));
mfichierWeb->close();
mfichierWeb->remove();
} else {
mfichierWeb->close();
}
delete mfichierWeb;
}
} |
Partager