PDA

View Full Version : probleme dowloading file with QFtp::get()



hbill
28th June 2008, 11:08
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 :o

here is the code of download :



void myMainWindow::downFileSlot()
{
QString fileName = serverDir->currentItem()->text(0);
if( currentServerDir[ fileName ] )
{
QMessageBox::information(this, tr("Client FTP"), tr("Vous devez selectionner un fichier source\n %1 est un dossier") .arg(fileName));
return;
}

QDirModel *dirMod = (QDirModel *)(localDir->model());
bool selectedIsDir = dirMod->fileInfo( localDir->currentIndex() ).isDir();
QString path = dirMod->fileInfo( localDir->currentIndex() ).absoluteFilePath();

if(selectedIsDir)
{
QFile *file = new QFile(path + "/" + fileName);


if ( QFile::exists(path + "/" + fileName) )
{
QMessageBox msgBox(QMessageBox::Warning, "FTP Erreur", "Le fichier " + fileName + " existe deja\nVoulez vous le remplacer ?", QMessageBox::Yes | QMessageBox::No, this);
switch ( msgBox.exec() )
{
case QMessageBox::Yes:
break;
case QMessageBox::No:
return;
break;
default:
return;
break;
}
}
if (!file->open(QIODevice::WriteOnly)) {
QMessageBox::information(this, tr("Client FTP"), tr("Impossible d'enregistrer le fichier %1: %2.") .arg(fileName).arg(file->errorString()));
delete file;
return;
}

ftp->get(fileName, file);
stopAction->setEnabled(true);
down=new MyTreeWidgetItem;
currentDown[ ftp->currentId() ] = down;
connect( ftp, SIGNAL( dataTransferProgress(qint64, qint64) ), currentDown[ ftp->currentId() ] , SLOT( progressTranferDataSlot(qint64, qint64) ) );
listDown->addTopLevelItem( currentDown[ ftp->currentId() ] );
currentDown[ ftp->currentId() ]->setLine(1, fileName);

dirMod->refresh();
}
else
{
QMessageBox::information(this, tr("Client FTP"), tr("Vous devez selectionner un dossier destinataire\n %1 est un fichier") .arg(path) );
}
}


can you help me pleaz
thanks

jpn
30th June 2008, 08:34
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()?

hbill
1st July 2008, 00:03
The dir model shows its size as 0 or its also empty on the disk? Have you tried checking QFtp::error() (http://doc.trolltech.com/latest/qftp.html#error) and/or QFtp::errorString() (http://doc.trolltech.com/latest/qftp.html#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) :crying:

QFtp::error() (http://doc.trolltech.com/latest/qftp.html#error) return 0 .

++

jpn
1st July 2008, 07:18
What actions do you take when the download finishes?

hbill
1st July 2008, 10:07
What actions do you take when the download finishes?




connect( ftp, SIGNAL( commandFinished (int, bool) ), this, SLOT( cmdFinishedSlot(int, bool) ) );

//...

void myMainWindow::cmdFinishedSlot(int cmd, bool error)
{
toParentServer->setEnabled(true);
toRootServer->setEnabled(true);
refreshServer->setEnabled(true);
newDirServer->setEnabled(true);
deleteDirFile->setEnabled(true);
renameFile->setEnabled(true);

downFile->setEnabled(true);
upFile->setEnabled(true);

stopAction->setEnabled(false);

setCursor(Qt::ArrowCursor);

if ( ftp->currentCommand() == QFtp::Get || ftp->currentCommand() == QFtp::Put )
{
disconnect( ftp, SIGNAL( dataTransferProgress(qint64, qint64) ), currentDown[ ftp->currentId() ] , SLOT( progressTranferDataSlot(qint64, qint64) ) );
if ( ftp->currentCommand() == QFtp::Put )
{
serverDir->clear();
currentServerDir.clear();
ftp->list();
}
else
{
QDirModel *dirMod = (QDirModel *)(localDir->model());
dirMod->refresh();
}
}
}


I try to do just


void myMainWindow::cmdFinishedSlot(int cmd, bool error)
{
toParentServer->setEnabled(true);
toRootServer->setEnabled(true);
refreshServer->setEnabled(true);
newDirServer->setEnabled(true);
deleteDirFile->setEnabled(true);
renameFile->setEnabled(true);

downFile->setEnabled(true);
upFile->setEnabled(true);

stopAction->setEnabled(false);

setCursor(Qt::ArrowCursor);
}

and i have the same problem

jpn
1st July 2008, 10:37
Hmm, is the file closed and/or the QFile object destructed anywhere?

hbill
3rd July 2008, 12:43
thanks

in th

void myMainWindow::cmdFinishedSlot(int cmd, bool error)
I delete the QFile* in

if ( ftp->currentCommand() == QFtp::Get || ftp->currentCommand() == QFtp::Put )

it work