Results 1 to 7 of 7

Thread: probleme dowloading file with QFtp::get()

  1. #1
    Join Date
    Mar 2008
    Posts
    21
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default probleme dowloading file with QFtp::get()

    hi
    I ty to download file from ftp server using QFtp::get(),
    my probelem is at the end of dowload, the file downloaded is empty

    here is the code of download :

    Qt Code:
    1. void myMainWindow::downFileSlot()
    2. {
    3. QString fileName = serverDir->currentItem()->text(0);
    4. if( currentServerDir[ fileName ] )
    5. {
    6. QMessageBox::information(this, tr("Client FTP"), tr("Vous devez selectionner un fichier source\n %1 est un dossier") .arg(fileName));
    7. return;
    8. }
    9.  
    10. QDirModel *dirMod = (QDirModel *)(localDir->model());
    11. bool selectedIsDir = dirMod->fileInfo( localDir->currentIndex() ).isDir();
    12. QString path = dirMod->fileInfo( localDir->currentIndex() ).absoluteFilePath();
    13.  
    14. if(selectedIsDir)
    15. {
    16. QFile *file = new QFile(path + "/" + fileName);
    17.  
    18.  
    19. if ( QFile::exists(path + "/" + fileName) )
    20. {
    21. QMessageBox msgBox(QMessageBox::Warning, "FTP Erreur", "Le fichier " + fileName + " existe deja\nVoulez vous le remplacer ?", QMessageBox::Yes | QMessageBox::No, this);
    22. switch ( msgBox.exec() )
    23. {
    24. case QMessageBox::Yes:
    25. break;
    26. case QMessageBox::No:
    27. return;
    28. break;
    29. default:
    30. return;
    31. break;
    32. }
    33. }
    34. if (!file->open(QIODevice::WriteOnly)) {
    35. QMessageBox::information(this, tr("Client FTP"), tr("Impossible d'enregistrer le fichier %1: %2.") .arg(fileName).arg(file->errorString()));
    36. delete file;
    37. return;
    38. }
    39.  
    40. ftp->get(fileName, file);
    41. stopAction->setEnabled(true);
    42. down=new MyTreeWidgetItem;
    43. currentDown[ ftp->currentId() ] = down;
    44. connect( ftp, SIGNAL( dataTransferProgress(qint64, qint64) ), currentDown[ ftp->currentId() ] , SLOT( progressTranferDataSlot(qint64, qint64) ) );
    45. listDown->addTopLevelItem( currentDown[ ftp->currentId() ] );
    46. currentDown[ ftp->currentId() ]->setLine(1, fileName);
    47.  
    48. dirMod->refresh();
    49. }
    50. else
    51. {
    52. QMessageBox::information(this, tr("Client FTP"), tr("Vous devez selectionner un dossier destinataire\n %1 est un fichier") .arg(path) );
    53. }
    54. }
    To copy to clipboard, switch view to plain text mode 

    can you help me pleaz
    thanks

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: probleme dowloading file with QFtp::get()

    The dir model shows its size as 0 or its also empty on the disk? Have you tried checking QFtp::error() and/or QFtp::errorString()?
    J-P Nurmi

  3. #3
    Join Date
    Mar 2008
    Posts
    21
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: probleme dowloading file with QFtp::get()

    Quote Originally Posted by jpn View Post
    The dir model shows its size as 0 or its also empty on the disk? Have you tried checking QFtp::error() and/or QFtp::errorString()?
    thanks

    in the dir model the size of files isn't 0, but dont have the real size, it have size less than the real size (for example: real size : 79 KB, size in dir model 64KB)

    QFtp::error() return 0 .

    ++

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: probleme dowloading file with QFtp::get()

    What actions do you take when the download finishes?
    J-P Nurmi

  5. #5
    Join Date
    Mar 2008
    Posts
    21
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: probleme dowloading file with QFtp::get()

    Quote Originally Posted by jpn View Post
    What actions do you take when the download finishes?

    Qt Code:
    1. connect( ftp, SIGNAL( commandFinished (int, bool) ), this, SLOT( cmdFinishedSlot(int, bool) ) );
    2.  
    3. //...
    4.  
    5. void myMainWindow::cmdFinishedSlot(int cmd, bool error)
    6. {
    7. toParentServer->setEnabled(true);
    8. toRootServer->setEnabled(true);
    9. refreshServer->setEnabled(true);
    10. newDirServer->setEnabled(true);
    11. deleteDirFile->setEnabled(true);
    12. renameFile->setEnabled(true);
    13.  
    14. downFile->setEnabled(true);
    15. upFile->setEnabled(true);
    16.  
    17. stopAction->setEnabled(false);
    18.  
    19. setCursor(Qt::ArrowCursor);
    20.  
    21. if ( ftp->currentCommand() == QFtp::Get || ftp->currentCommand() == QFtp::Put )
    22. {
    23. disconnect( ftp, SIGNAL( dataTransferProgress(qint64, qint64) ), currentDown[ ftp->currentId() ] , SLOT( progressTranferDataSlot(qint64, qint64) ) );
    24. if ( ftp->currentCommand() == QFtp::Put )
    25. {
    26. serverDir->clear();
    27. currentServerDir.clear();
    28. ftp->list();
    29. }
    30. else
    31. {
    32. QDirModel *dirMod = (QDirModel *)(localDir->model());
    33. dirMod->refresh();
    34. }
    35. }
    36. }
    To copy to clipboard, switch view to plain text mode 


    I try to do just

    Qt Code:
    1. void myMainWindow::cmdFinishedSlot(int cmd, bool error)
    2. {
    3. toParentServer->setEnabled(true);
    4. toRootServer->setEnabled(true);
    5. refreshServer->setEnabled(true);
    6. newDirServer->setEnabled(true);
    7. deleteDirFile->setEnabled(true);
    8. renameFile->setEnabled(true);
    9.  
    10. downFile->setEnabled(true);
    11. upFile->setEnabled(true);
    12.  
    13. stopAction->setEnabled(false);
    14.  
    15. setCursor(Qt::ArrowCursor);
    16. }
    To copy to clipboard, switch view to plain text mode 

    and i have the same problem

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: probleme dowloading file with QFtp::get()

    Hmm, is the file closed and/or the QFile object destructed anywhere?
    J-P Nurmi

  7. #7
    Join Date
    Mar 2008
    Posts
    21
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: probleme dowloading file with QFtp::get()

    thanks

    in th
    Qt Code:
    1. void myMainWindow::cmdFinishedSlot(int cmd, bool error)
    To copy to clipboard, switch view to plain text mode 
    I delete the QFile* in
    Qt Code:
    1. if ( ftp->currentCommand() == QFtp::Get || ftp->currentCommand() == QFtp::Put )
    To copy to clipboard, switch view to plain text mode 

    it work

Similar Threads

  1. Set up the Qt4.3.2 with Visual Studio 2005
    By lamoda in forum Installation and Deployment
    Replies: 6
    Last Post: 30th January 2008, 06:51
  2. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 15:21

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.