Hi everyone.

I want to upload a file and sometimes this "upload" doesn't work fine. I have tried to catch the error but I haven't succeeded.I just need that when the file doesn't upload the function upload returns FALSE.

That is my code
Qt Code:
  1. void FileUploader::ftpCommandFinished(int id, bool error){
  2. if (myUploader->currentCommand() == QFtp::ConnectToHost) {
  3. if (error){
  4. printf("upload file resume ERROR: %s\n",myUploader->errorString().toAscii().data());
  5. myUploader->abort();
  6. myUploader->deleteLater();
  7. myUploader = 0;
  8. return;
  9. }else
  10. //if (id == login)
  11. myFile->remove("data/Tests/" + m_fileName +".csv");
  12. /*else if (id == connectToHost)
  13. printf("connectToHost finished\n");
  14. else if (id == get)
  15. printf("get finished\n");*/
  16. }else if (myUploader->currentCommand() == QFtp::Login){
  17. if (error){
  18. printf("upload file resume ERROR: %s\n",myUploader->errorString().toAscii().data());
  19. myUploader->abort();
  20. myUploader->deleteLater();
  21. myUploader = 0;
  22. return;
  23. }else
  24. //if (id == login)
  25. myFile->remove("data/Tests/" + m_fileName +".csv");
  26. }else if (myUploader->currentCommand() == QFtp::Put){
  27. if (error){
  28. printf("upload file resume ERROR: %s\n",myUploader->errorString().toAscii().data());
  29. myUploader->abort();
  30. myUploader->deleteLater();
  31. myUploader = 0;
  32. return;
  33. }else
  34. //if (id == login)
  35. myFile->remove("data/Tests/" + m_fileName +".csv");
  36. }
  37. }
  38.  
  39. bool FileUploader::upload(QString fileName,accountInfoSettings* myAccountInfoSettings){
  40.  
  41. myUploader = new QFtp();
  42. /*bool error = FileUploader::zip(fileName);
  43. if(!error){
  44.  
  45. printf("error del bueno\n");
  46. fflush(stdout);
  47. }
  48.  
  49. printf("Zip file created\n");
  50. fflush(stdout);*/
  51.  
  52. myFile = new QFile("data/Tests/" +fileName); //.remove(".csv")+".zip");
  53.  
  54. m_fileName = fileName;
  55. myFile->open(QFile::ReadOnly);
  56. connect(myUploader, SIGNAL(commandFinished(int,bool)), this, SLOT(ftpCommandFinished(int,bool)));
  57. /*myUploader->connectToHost("www.at4wireless.com",21); myUploader->login("demo_at4","H3mEwwUC");*/
  58. myUploader->connectToHost(myAccountInfoSettings->getUrl(),21);
  59. myUploader->login(myAccountInfoSettings->getUser(),myAccountInfoSettings->getPassword());
  60. myUploader->put(myFile,fileName);
  61. printf("Put\n"); fflush(stdout);
  62.  
  63. if (QFtp::UnknownError == myUploader->error() || QFtp::HostNotFound == myUploader->error() ||
  64. QFtp::ConnectionRefused == myUploader->error() || QFtp::NotConnected == myUploader->error())
  65. return false;
  66. else return true;
  67. }
To copy to clipboard, switch view to plain text mode 

Any help is welcome

Thanks again, Carmen.