void FileUploader::ftpCommandFinished(int id, bool error){
if (myUploader
->currentCommand
() == QFtp::ConnectToHost) { if (error){
printf("upload file resume ERROR: %s\n",myUploader->errorString().toAscii().data());
myUploader->abort();
myUploader->deleteLater();
myUploader = 0;
return;
}else
//if (id == login)
myFile->remove("data/Tests/" + m_fileName +".csv");
/*else if (id == connectToHost)
printf("connectToHost finished\n");
else if (id == get)
printf("get finished\n");*/
}else if (myUploader
->currentCommand
() == QFtp::Login){ if (error){
printf("upload file resume ERROR: %s\n",myUploader->errorString().toAscii().data());
myUploader->abort();
myUploader->deleteLater();
myUploader = 0;
return;
}else
//if (id == login)
myFile->remove("data/Tests/" + m_fileName +".csv");
}else if (myUploader
->currentCommand
() == QFtp::Put){ if (error){
printf("upload file resume ERROR: %s\n",myUploader->errorString().toAscii().data());
myUploader->abort();
myUploader->deleteLater();
myUploader = 0;
return;
}else
//if (id == login)
myFile->remove("data/Tests/" + m_fileName +".csv");
}
}
bool FileUploader
::upload(QString fileName,accountInfoSettings
* myAccountInfoSettings
){
/*bool error = FileUploader::zip(fileName);
if(!error){
printf("error del bueno\n");
fflush(stdout);
}
printf("Zip file created\n");
fflush(stdout);*/
myFile
= new QFile("data/Tests/" +fileName
);
//.remove(".csv")+".zip");
m_fileName = fileName;
myFile
->open
(QFile::ReadOnly);
connect(myUploader, SIGNAL(commandFinished(int,bool)), this, SLOT(ftpCommandFinished(int,bool)));
/*myUploader->connectToHost("www.at4wireless.com",21); myUploader->login("demo_at4","H3mEwwUC");*/
myUploader->connectToHost(myAccountInfoSettings->getUrl(),21);
myUploader->login(myAccountInfoSettings->getUser(),myAccountInfoSettings->getPassword());
myUploader->put(myFile,fileName);
printf("Put\n"); fflush(stdout);
if (QFtp::UnknownError == myUploader
->error
() ||
QFtp::HostNotFound == myUploader
->error
() ||
QFtp::ConnectionRefused == myUploader
->error
() ||
QFtp::NotConnected == myUploader
->error
()) return false;
else return true;
}
void FileUploader::ftpCommandFinished(int id, bool error){
if (myUploader->currentCommand() == QFtp::ConnectToHost) {
if (error){
printf("upload file resume ERROR: %s\n",myUploader->errorString().toAscii().data());
myUploader->abort();
myUploader->deleteLater();
myUploader = 0;
return;
}else
//if (id == login)
myFile->remove("data/Tests/" + m_fileName +".csv");
/*else if (id == connectToHost)
printf("connectToHost finished\n");
else if (id == get)
printf("get finished\n");*/
}else if (myUploader->currentCommand() == QFtp::Login){
if (error){
printf("upload file resume ERROR: %s\n",myUploader->errorString().toAscii().data());
myUploader->abort();
myUploader->deleteLater();
myUploader = 0;
return;
}else
//if (id == login)
myFile->remove("data/Tests/" + m_fileName +".csv");
}else if (myUploader->currentCommand() == QFtp::Put){
if (error){
printf("upload file resume ERROR: %s\n",myUploader->errorString().toAscii().data());
myUploader->abort();
myUploader->deleteLater();
myUploader = 0;
return;
}else
//if (id == login)
myFile->remove("data/Tests/" + m_fileName +".csv");
}
}
bool FileUploader::upload(QString fileName,accountInfoSettings* myAccountInfoSettings){
myUploader = new QFtp();
/*bool error = FileUploader::zip(fileName);
if(!error){
printf("error del bueno\n");
fflush(stdout);
}
printf("Zip file created\n");
fflush(stdout);*/
myFile = new QFile("data/Tests/" +fileName); //.remove(".csv")+".zip");
m_fileName = fileName;
myFile->open(QFile::ReadOnly);
connect(myUploader, SIGNAL(commandFinished(int,bool)), this, SLOT(ftpCommandFinished(int,bool)));
/*myUploader->connectToHost("www.at4wireless.com",21); myUploader->login("demo_at4","H3mEwwUC");*/
myUploader->connectToHost(myAccountInfoSettings->getUrl(),21);
myUploader->login(myAccountInfoSettings->getUser(),myAccountInfoSettings->getPassword());
myUploader->put(myFile,fileName);
printf("Put\n"); fflush(stdout);
if (QFtp::UnknownError == myUploader->error() || QFtp::HostNotFound == myUploader->error() ||
QFtp::ConnectionRefused == myUploader->error() || QFtp::NotConnected == myUploader->error())
return false;
else return true;
}
To copy to clipboard, switch view to plain text mode
Bookmarks