#include "FTPconnect.h"
#include "deviceroutine.h"
#include <QMessageBox>
FTPconnect
::FTPconnect(Ui
::DeviceRoutineClass *ui,
QWidget *parent, Qt
::WFlags flags
) : DeviceRoutine
(parent, flags
){
//Zeiger auf UI setzen
this->ui=ui;
file=NULL;
dircount=0;
}
FTPconnect::~FTPconnect(){}
void FTPconnect::ftp_start(){
ui->textEdit_ausgabe_FTP->setText("");
abgebrochen=false;
if((is_directory(ui->lineEdit_FTP_pfad->text().toStdString())==0) && (ui->lineEdit_FTP_pfad->isEnabled()==1)){
//Dann breche die Aktion ab und wähle neuen Pfad
ui->textEdit_ausgabe_FTP->append("------------------------------------------------------------------------------------\n") ;
ui->textEdit_ausgabe_FTP->append("Kein gueltiger FTP Ausgabepfad angegeben! Bitte aendern...\n");
ui->textEdit_ausgabe_FTP->append("------------------------------------------------------------------------------------\n");
//wähle neuen Pfad
return;
}
progress
= new QProgressDialog("Analysiere Verzeichnisstruktur...",
"Abbrechen",
0,
100,
this);
progress->setAutoReset(0);
//Ftp bereistellen
ftpzeiger
->setTransferMode
(QFtp::Active);
connect(ftpzeiger, SIGNAL(done(bool)), this, SLOT(getdirectories_ende()));
connect(ftpzeiger, SIGNAL(dataTransferProgress(qint64, qint64)), this, SLOT(ftp_progress(qint64,qint64)));
connect(ftpzeiger, SIGNAL(commandStarted(int)),this, SLOT(ftp_CommandStarted(int)));
connect(ftpzeiger, SIGNAL(commandFinished(int,bool)),this, SLOT(ftp_CommandFinished(int,bool)));
//Hole nur Verzeichnisse
connect(ftpzeiger,
SIGNAL(listInfo
(QUrlInfo)),
this,
SLOT(getdirectories
(QUrlInfo)));
//Host aus dem Lineedit holen
this->ftpzeiger->connectToHost(ui->lineEdit_host->text());
//Logindaten - Wenn beide Felder leer --> anonymous Login
if ((ui->lineEdit_login->text())=="" && (ui->lineEdit_passwort->text()==""))
ftpzeiger->login();
else
ftpzeiger->login(ui->lineEdit_login->text(),ui->lineEdit_passwort->text());
if (ui->lineEdit_verzeichnis->text()==0){
ui->textEdit_ausgabe_FTP->append("Bitte ein Verzeichnis angeben...");
this->~FTPconnect();
return;
}
//Verzeichnis auswählen
ftpzeiger->cd(ui->lineEdit_verzeichnis->text());
//Directory Listing
ftpzeiger->list();
//Event Schleife
progress->exec();
if(directorylist.size()==0)
ui->textEdit_ausgabe_FTP->append("Keine gueltigen Dateien gefunden...\n");
//Events für Ende und Datenübertragung
connect(ftpzeiger, SIGNAL(done(bool)), this, SLOT(ftp_ende()));
//Trenne nicht mehr benötigte Signale
disconnect(ftpzeiger, SIGNAL(done(bool)), this, SLOT(getdirectories_ende()));
disconnect
(ftpzeiger,
SIGNAL(listInfo
(QUrlInfo)),
this,
SLOT(getdirectories
(QUrlInfo)));
//Hole nur noch Dateien
//Für jede gefundenen Ordner
for(dircount=0;dircount<directorylist.size();dircount++){
progress
= new QProgressDialog("Kopiere Dateien...",
"Abbrechen",
0,
100,
this);
//connect(progress, SIGNAL(canceled()), this, SLOT(ftp_abort()));
//Verzeichnis und File auswählen
ftpzeiger->cd(ui->lineEdit_verzeichnis->text() + "/" + directorylist[dircount]);
//Dateien werden gesucht - intern
ftpzeiger->list();
ui->textEdit_ausgabe_FTP->append("Verzeichnis:" + directorylist[dircount]);
progress->exec();
}
}
void FTPconnect::ftp_ende(){
if (abgebrochen==1){
ui->textEdit_ausgabe_FTP->append("\nDownload abgebrochen!");
}
if(ftpzeiger->error()==0)
ui->textEdit_ausgabe_FTP->append("Datei erfolgreich heruntergeladen!");
else
ui->textEdit_ausgabe_FTP->append(this->ftpzeiger->errorString());
//Aufräumen
this->progress->close();
this->progress->deleteLater();
this->progress=NULL;
}
//setze DL Fortschritt in Progressbar um
void FTPconnect::ftp_progress(qint64 done,qint64 total){
this->progress->setMaximum(total);
this->progress->setValue(done);
}
void FTPconnect::ftp_CommandFinished(int, bool error){
if (ftpzeiger
->currentCommand
() == QFtp::ConnectToHost) { ui->textEdit_ausgabe_FTP->append("Verbindung zum Host aufgebaut...\n");
if (error){
ui->textEdit_ausgabe_FTP->append(ftpzeiger->errorString ());
this->progress->close();
}
}
if (ftpzeiger
->currentCommand
() == QFtp::Login){ ui->textEdit_ausgabe_FTP->append("Logindaten ueberprüft...\n");
if (error){
ui->textEdit_ausgabe_FTP->append(ftpzeiger->errorString ());
this->progress->close();
}
}
if (ftpzeiger
->currentCommand
() == QFtp::Get) {
ui->textEdit_ausgabe_FTP->append("Datenuebertragung beendet...\n");
if (error) {
ui->textEdit_ausgabe_FTP->append(ftpzeiger->errorString ());
ftpzeiger->abort();
this->progress->close();
file->close();
file->remove();
}
}
if (ftpzeiger
->currentCommand
() == QFtp::List) { ui->textEdit_ausgabe_FTP->append("Verzeichnisse eingelesen...\n");
if (error) {
ui->textEdit_ausgabe_FTP->append(ftpzeiger->errorString ());
ftpzeiger->abort();
this->progress->close();
}
}
}
void FTPconnect::ftp_CommandStarted(int id){
if (ftpzeiger
->currentCommand
() == QFtp::ConnectToHost) ui->textEdit_ausgabe_FTP->append("Verbindung zum Host wird aufgebaut...");
if (ftpzeiger
->currentCommand
() == QFtp::Login) ui->textEdit_ausgabe_FTP->append("Logindaten werden ueberprüft...");
if (ftpzeiger
->currentCommand
() == QFtp::Get) ui->textEdit_ausgabe_FTP->append("Datenuebertragung gestartet...");
if (ftpzeiger
->currentCommand
() == QFtp::List) ui->textEdit_ausgabe_FTP->append("Lese Verzeichniss ein...");
}
void FTPconnect::ftp_abort(){
this->ftpzeiger->abort();
this->progress->close();
abgebrochen=1;
}
void FTPconnect
::getfiles(const QUrlInfo &urlInfo
){ //Wenn devlist oder devparm ist
if ((urlInfo.isDir()==false) && ((urlInfo.name()=="devList.dat") || (urlInfo.name()=="devParm.dat"))){
if (ui->radioButton_FTP_eigen->isChecked()){
//Wenn der Rezeptordner nicht existiert,lege ihn an
if(is_directory(ui->lineEdit_FTP_pfad->text().toStdString() + "\\" + directorylist[dircount].toStdString())==false)
create_directory(ui->lineEdit_FTP_pfad->text().toStdString() + "\\" + directorylist[dircount].toStdString());
progress->setLabelText("Downloade " + directorylist[dircount] + "...");
ui->textEdit_ausgabe_FTP->append("Downloade " + urlInfo.name() + "...");
//File zum schreiben/lesen öffnen
file = new QFile(ui
->lineEdit_FTP_pfad
->text
() + "\\" + directorylist
[dircount
] + "\\" + urlInfo.
name() );
ftpzeiger->get(urlInfo.name(),file);
}
//Standartausgabe nach FTP
else{
//Wenn FTP noch nicht existiert, lege es an
if(is_directory("FTP")==false)
create_directory("FTP");
//Wenn der Rezeptordner nicht existiert,lege ihn an
if(is_directory("FTP\\" + directorylist[dircount].toStdString())==false)
create_directory("FTP\\" + directorylist[dircount].toStdString());
progress->setLabelText("Downloade " + directorylist[dircount] + "...");
ui->textEdit_ausgabe_FTP->append("Downloade " + urlInfo.name() + "...");
/* Hier später auf DevList und DevParm prüfen */
//File zum schreiben/lesen öffnen
file = new QFile("FTP\\" + directorylist
[dircount
] + "\\" + urlInfo.
name() );
ftpzeiger->get(urlInfo.name(),file);
}
}
}
void FTPconnect
::getdirectories(const QUrlInfo &urlInfo
){
//Wenn Verzeichnis ist (aber kein . oder ..)
if ((urlInfo.isDir()==true) && (urlInfo.name()!=".") && (urlInfo.name()!=".."))
directorylist.push_back(urlInfo.name());
}
void FTPconnect::getdirectories_ende(){
//Aufräumen
this->progress->close();
this->progress=NULL;
}
#include "FTPconnect.h"
#include "deviceroutine.h"
#include <QMessageBox>
FTPconnect::FTPconnect(Ui::DeviceRoutineClass *ui,QWidget *parent, Qt::WFlags flags) : DeviceRoutine(parent, flags){
//Zeiger auf UI setzen
this->ui=ui;
file=NULL;
dircount=0;
}
FTPconnect::~FTPconnect(){}
void FTPconnect::ftp_start(){
ui->textEdit_ausgabe_FTP->setText("");
abgebrochen=false;
if((is_directory(ui->lineEdit_FTP_pfad->text().toStdString())==0) && (ui->lineEdit_FTP_pfad->isEnabled()==1)){
//Dann breche die Aktion ab und wähle neuen Pfad
ui->textEdit_ausgabe_FTP->append("------------------------------------------------------------------------------------\n") ;
ui->textEdit_ausgabe_FTP->append("Kein gueltiger FTP Ausgabepfad angegeben! Bitte aendern...\n");
ui->textEdit_ausgabe_FTP->append("------------------------------------------------------------------------------------\n");
//wähle neuen Pfad
return;
}
progress= new QProgressDialog("Analysiere Verzeichnisstruktur...", "Abbrechen", 0, 100, this);
progress->setAutoReset(0);
//Ftp bereistellen
ftpzeiger = new QFtp();
ftpzeiger->setTransferMode(QFtp::Active);
connect(ftpzeiger, SIGNAL(done(bool)), this, SLOT(getdirectories_ende()));
connect(ftpzeiger, SIGNAL(dataTransferProgress(qint64, qint64)), this, SLOT(ftp_progress(qint64,qint64)));
connect(ftpzeiger, SIGNAL(commandStarted(int)),this, SLOT(ftp_CommandStarted(int)));
connect(ftpzeiger, SIGNAL(commandFinished(int,bool)),this, SLOT(ftp_CommandFinished(int,bool)));
//Hole nur Verzeichnisse
connect(ftpzeiger, SIGNAL(listInfo(QUrlInfo)),this, SLOT(getdirectories(QUrlInfo)));
//Host aus dem Lineedit holen
this->ftpzeiger->connectToHost(ui->lineEdit_host->text());
//Logindaten - Wenn beide Felder leer --> anonymous Login
if ((ui->lineEdit_login->text())=="" && (ui->lineEdit_passwort->text()==""))
ftpzeiger->login();
else
ftpzeiger->login(ui->lineEdit_login->text(),ui->lineEdit_passwort->text());
if (ui->lineEdit_verzeichnis->text()==0){
ui->textEdit_ausgabe_FTP->append("Bitte ein Verzeichnis angeben...");
this->~FTPconnect();
return;
}
//Verzeichnis auswählen
ftpzeiger->cd(ui->lineEdit_verzeichnis->text());
//Directory Listing
ftpzeiger->list();
//Event Schleife
progress->exec();
if(directorylist.size()==0)
ui->textEdit_ausgabe_FTP->append("Keine gueltigen Dateien gefunden...\n");
//Events für Ende und Datenübertragung
connect(ftpzeiger, SIGNAL(done(bool)), this, SLOT(ftp_ende()));
//Trenne nicht mehr benötigte Signale
disconnect(ftpzeiger, SIGNAL(done(bool)), this, SLOT(getdirectories_ende()));
disconnect(ftpzeiger, SIGNAL(listInfo(QUrlInfo)),this, SLOT(getdirectories(QUrlInfo)));
//Hole nur noch Dateien
connect(ftpzeiger, SIGNAL(listInfo(QUrlInfo)),this, SLOT(getfiles(QUrlInfo)));
//Für jede gefundenen Ordner
for(dircount=0;dircount<directorylist.size();dircount++){
progress= new QProgressDialog("Kopiere Dateien...", "Abbrechen", 0, 100, this);
//connect(progress, SIGNAL(canceled()), this, SLOT(ftp_abort()));
//Verzeichnis und File auswählen
ftpzeiger->cd(ui->lineEdit_verzeichnis->text() + "/" + directorylist[dircount]);
//Dateien werden gesucht - intern
ftpzeiger->list();
ui->textEdit_ausgabe_FTP->append("Verzeichnis:" + directorylist[dircount]);
progress->exec();
}
}
void FTPconnect::ftp_ende(){
if (abgebrochen==1){
ui->textEdit_ausgabe_FTP->append("\nDownload abgebrochen!");
}
if(ftpzeiger->error()==0)
ui->textEdit_ausgabe_FTP->append("Datei erfolgreich heruntergeladen!");
else
ui->textEdit_ausgabe_FTP->append(this->ftpzeiger->errorString());
//Aufräumen
this->progress->close();
this->progress->deleteLater();
this->progress=NULL;
}
//setze DL Fortschritt in Progressbar um
void FTPconnect::ftp_progress(qint64 done,qint64 total){
this->progress->setMaximum(total);
this->progress->setValue(done);
}
void FTPconnect::ftp_CommandFinished(int, bool error){
if (ftpzeiger->currentCommand() == QFtp::ConnectToHost) {
ui->textEdit_ausgabe_FTP->append("Verbindung zum Host aufgebaut...\n");
if (error){
ui->textEdit_ausgabe_FTP->append(ftpzeiger->errorString ());
this->progress->close();
}
}
if (ftpzeiger->currentCommand() == QFtp::Login){
ui->textEdit_ausgabe_FTP->append("Logindaten ueberprüft...\n");
if (error){
ui->textEdit_ausgabe_FTP->append(ftpzeiger->errorString ());
this->progress->close();
}
}
if (ftpzeiger->currentCommand() == QFtp::Get) {
ui->textEdit_ausgabe_FTP->append("Datenuebertragung beendet...\n");
if (error) {
ui->textEdit_ausgabe_FTP->append(ftpzeiger->errorString ());
ftpzeiger->abort();
this->progress->close();
file->close();
file->remove();
}
}
if (ftpzeiger->currentCommand() == QFtp::List) {
ui->textEdit_ausgabe_FTP->append("Verzeichnisse eingelesen...\n");
if (error) {
ui->textEdit_ausgabe_FTP->append(ftpzeiger->errorString ());
ftpzeiger->abort();
this->progress->close();
}
}
}
void FTPconnect::ftp_CommandStarted(int id){
if (ftpzeiger->currentCommand() == QFtp::ConnectToHost)
ui->textEdit_ausgabe_FTP->append("Verbindung zum Host wird aufgebaut...");
if (ftpzeiger->currentCommand() == QFtp::Login)
ui->textEdit_ausgabe_FTP->append("Logindaten werden ueberprüft...");
if (ftpzeiger->currentCommand() == QFtp::Get)
ui->textEdit_ausgabe_FTP->append("Datenuebertragung gestartet...");
if (ftpzeiger->currentCommand() == QFtp::List)
ui->textEdit_ausgabe_FTP->append("Lese Verzeichniss ein...");
}
void FTPconnect::ftp_abort(){
this->ftpzeiger->abort();
this->progress->close();
abgebrochen=1;
}
void FTPconnect::getfiles(const QUrlInfo &urlInfo){
//Wenn devlist oder devparm ist
if ((urlInfo.isDir()==false) && ((urlInfo.name()=="devList.dat") || (urlInfo.name()=="devParm.dat"))){
if (ui->radioButton_FTP_eigen->isChecked()){
//Wenn der Rezeptordner nicht existiert,lege ihn an
if(is_directory(ui->lineEdit_FTP_pfad->text().toStdString() + "\\" + directorylist[dircount].toStdString())==false)
create_directory(ui->lineEdit_FTP_pfad->text().toStdString() + "\\" + directorylist[dircount].toStdString());
progress->setLabelText("Downloade " + directorylist[dircount] + "...");
ui->textEdit_ausgabe_FTP->append("Downloade " + urlInfo.name() + "...");
//File zum schreiben/lesen öffnen
file = new QFile(ui->lineEdit_FTP_pfad->text() + "\\" + directorylist[dircount] + "\\" + urlInfo.name() );
file->open(QIODevice::WriteOnly);
ftpzeiger->get(urlInfo.name(),file);
}
//Standartausgabe nach FTP
else{
//Wenn FTP noch nicht existiert, lege es an
if(is_directory("FTP")==false)
create_directory("FTP");
//Wenn der Rezeptordner nicht existiert,lege ihn an
if(is_directory("FTP\\" + directorylist[dircount].toStdString())==false)
create_directory("FTP\\" + directorylist[dircount].toStdString());
progress->setLabelText("Downloade " + directorylist[dircount] + "...");
ui->textEdit_ausgabe_FTP->append("Downloade " + urlInfo.name() + "...");
/* Hier später auf DevList und DevParm prüfen */
//File zum schreiben/lesen öffnen
file = new QFile("FTP\\" + directorylist[dircount] + "\\" + urlInfo.name() );
file->open(QIODevice::ReadWrite);
ftpzeiger->get(urlInfo.name(),file);
}
}
}
void FTPconnect::getdirectories(const QUrlInfo &urlInfo){
//Wenn Verzeichnis ist (aber kein . oder ..)
if ((urlInfo.isDir()==true) && (urlInfo.name()!=".") && (urlInfo.name()!=".."))
directorylist.push_back(urlInfo.name());
}
void FTPconnect::getdirectories_ende(){
//Aufräumen
this->progress->close();
this->progress=NULL;
}
To copy to clipboard, switch view to plain text mode
Bookmarks