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
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