QFtp- can't download file I've just uploaded
-
Hi everyone,
I'm working on a simple program, based on QFtp. The purpose of it's work is to store small flies on FTP server.
I've wrote well working instructions for uploading and downloading files. Until I only download files by this program, things go alright (despite of progress pop-up showing twice). If I upload files and check if they are correctly uploaded by FTP client, I can see them and download (still by some ftp client), they aren't corrupted. Problem starts, when I try to download files uploaded before using only my program. When download progress starts, everything looks good but when it finishes I can only find empty file titled as downloaded file.
I would be very grateful if anyone got some idea.Here's the code I use to upload and download:
@
void SimpleCloud::wyslij()
{
QString sciezka = ui->Usciezka->text();
QString nazwa="";
int a=0,i=0;
for(i =0; i<sciezka.size(); i++)
{
if(sciezka.at(i)=='/')
{
qDebug()<<"slash na pozycji "<<i;
a=i+1;
}
}
qDebug()<<"n";
for(i=a;i<sciezka.size();i++)
{
nazwa[i-a]=sciezka[i];
}
qDebug()<<"nazwa pliku to: "<<nazwa;
plik = new QFile(sciezka);
ftp->put(plik,nazwa);
postep->setLabelText("Wysylanie "+nazwa);
postep->exec();
ui->statusBar->showMessage("Wysylanie");
qDebug()<<"FTP: wysylanie";
}void SimpleCloud::pobierz()
{
QString nazwa = ui->listaSerwer->currentItem()->text(0);
QString sciezka = ui->Dsciezka->text();
if(sciezka!="Ścieżka"&&sciezka!=NULL)
{
sciezka = sciezka + "/" + nazwa;
plik = new QFile(sciezka);
}
else
{
plik = new QFile(nazwa);
}
if(!plik->open(QFile::WriteOnly))
{
ui->statusBar->showMessage("Blad pobierania pliku",1000);
delete plik;
return;
}
ui->statusBar->showMessage("Rozpoczynam pobieranie");
ftp->get(ui->listaSerwer->currentItem()->text(0), plik);
postep->setLabelText("Pobieranie "+nazwa);
postep->exec();
}
@Edit
In this code I've used Polish to name variables, methods etc. If necessary I can translate that to English.[EDIT: code formatting, please use @-tags instead of [code], Volker]
-
Hi,
i dont react on your code, but i find it very helpfull to connect the ftp.done() to your own code and then you can see if theres a problem at ftp side. like the example program does.@
in .h
signals:
done();private slots:
void ftpDone(bool error);
in constructor:
connect(&ftp, SIGNAL(done(bool)),this,SLOT(ftpDone(bool)));in slot:
void SimpleCloud::ftpDone(bool error)
{
if (error) {
std::cerr << "ERROR: " << qPrintable(ftp.errorString())
<< std::endl;
} else {
std::cerr << "File downloaded as "
<< qPrintable(plik.fileName())
<< std::endl;
}
plik.close();
emit done();
}@
-
I did as you said and my program is unexpectedly stopping. I'll what have I done wrong and try to build it.
edit
It seems that I've got a segmentation fault while connecting done(bool) with ftpDone(bool) -
did you include iostream to use std:cerr?
-
No, I've used qDebug(); which I'm using in whole project. As I edited my previous post it's about connecting. What could be wrong?
-
my quess is that the filename is wrong, i did also encounterd that. But that was retrieving the name out of an url. So slightly dfferent, cause you select it.
make sure the name is not "/file.name" but "file.name" -
[quote author="jaszczomb" date="1306339228"]I did as you said and my program is unexpectedly stopping. I'll what have I done wrong and try to build it.
edit
It seems that I've got a segmentation fault while connecting done(bool) with ftpDone(bool)[/quote]-sorry dont know,
it works with me-i edited my last code, change in .h
-
You mean filename while uploading or downloading the file?
While sending file to FTP server I'm checking filename at
@
QString sciezka = ui->Usciezka->text();
QString nazwa="";
int a=0,i=0;
for(i =0; i<sciezka.size(); i++)
{
if(sciezka.at(i)=='/')
{
qDebug()<<"slash na pozycji "<<i;
a=i+1;
}
}
qDebug()<<"\n";
for(i=a;i<sciezka.size();i++)
{
nazwa[i-a]=sciezka[i];
}
qDebug()<<"nazwa pliku to: "<<nazwa;@
And filename at last line is correct, without slash. I can also download file (by FTP client as gFTP) I've uploaded using by my program so I don't think that's about filename.edit
is that possible that's about Qt Creator version or OS? -
Refreshing