Re: How to connect to ftp server and read the filenames in the ftp folder?
Quote:
Originally Posted by
wysota
Show the actual code, please.
Code:
localDir = "/home/nn";
QUrl url
("ftp://192.168.1.146");
ftp->connectToHost(url.host(),url.port(21));
ftp->login();
connect(ftp, SIGNAL(commandFinished(int,bool)), this, SLOT(ftpCommandFinished(int,bool)));
Code:
void MainWindow::ftpCommandFinished(int, bool error)
{
if(ftp
->currentCommand
() == QFtp::ConnectToHost) {
ftp->login();
}
if(ftp
->currentCommand
() == QFtp::Login) {
ftp->list();
}
if(ftp
->currentCommand
() == QFtp::Get) {
file->close();
}
if(ftp
->currentCommand
() == QFtp::List) {
download(listF);
}
}
Code:
void MainWindow
::ftpListInfo(QUrlInfo urlInfo
) {
if(urlInfo.isFile() && urlInfo.isReadable())
{
listF.append(urlInfo);
}
}
Code:
void MainWindow::download(QList<QUrlInfo> listF)
{
if(urlInfo.isFile() && urlInfo.isReadable())
{
file = new QFile(localDir
+ "/" + urlInfo.
name());
ftp->get(urlInfo.name(), file);
}
}
Re: How to connect to ftp server and read the filenames in the ftp folder?
You're not checking that each file actually gets downloaded. When you get commandFinished() after "get", you close "file" which is a global variable. Since QFtp::get() only schedules a download, your foreach loop completes before the first download is even started. As a result you end up with "file" assigned with the file belonging to the last "get" request but when the first "get" request completes, you close the last file (and not the first one, so the first one remains open and the last one is closed with 0 size). You need to pay attention to what QFtp::get() returns and associate it with the file handler so that you can retrieve the handle back when you receive commandFinished() signal. And fix those memory leaks.
Re: How to connect to ftp server and read the filenames in the ftp folder?
Quote:
Originally Posted by
wysota
You're not checking that each file actually gets downloaded. When you get commandFinished() after "get", you close "file" which is a global variable. Since
QFtp::get() only schedules a download, your foreach loop completes before the first download is even started. As a result you end up with "file" assigned with the file belonging to the last "get" request but when the first "get" request completes, you close the last file (and not the first one). You need to pay attention to what
QFtp::get() returns and associate it with the file handler so that you can retrieve the handle back when you receive commandFinished() signal. And fix those memory leaks.
Ok, i will try that. thanks
Re: How to connect to ftp server and read the filenames in the ftp folder?
Your code is wrong. Period.
Re: How to connect to ftp server and read the filenames in the ftp folder?
Quote:
Originally Posted by
wysota
Your code is wrong. Period.
I got it... the problem solved.
Re: How to connect to ftp server and read the filenames in the ftp folder?
Hi wysota,
My ftp application is working fine in my desktop machines, whereas i am getting the problem in My touchscreen device. Which consists of Debian Linux.
when i run the ftp application in the device its showing an error message as follows :
Quote:
./qftp: symbol lookup error: ./qftp: undefined symbol: _ZN9QListData11detach_growEPii
why it is happening i am not able to find ?
Added after 59 minutes:
I got it problem solved.
Re: How to connect to ftp server and read the filenames in the ftp folder?
Hi wysota,
While using ftp in my device it saying "Read-Only file system".
i even tried it by giving the folder and files read write permissions, then also i am unable to copy the files from my PC to the Device.
Re: How to connect to ftp server and read the filenames in the ftp folder?
And what exactly do you want me to do about it? :) Your filesystem is probably mounted read-only.