-
How to connect to ftp server and read the filenames in the ftp folder?
How to connect to ftp server and read the filenames from the ftp folder and create labels with the filenames and display those on the dialog?
-
Re: How to connect to ftp server and read the filenames in the ftp folder?
-
Re: How to connect to ftp server and read the filenames in the ftp folder?
I have just made the connection using ftp. How to read the filenames in the particular folder?
-
Re: How to connect to ftp server and read the filenames in the ftp folder?
Issue the FTP LIST command. So far you have not explained how you have tried to use Qt to do any of this.
-
Re: How to connect to ftp server and read the filenames in the ftp folder?
I have added the following code to login into the ftp site.
Code:
ftp->connectToHost("ftp.qt.nokia.com");
ftp->login();
-
Re: How to connect to ftp server and read the filenames in the ftp folder?
And then? Have you seen QFtp::list()?
-
Re: How to connect to ftp server and read the filenames in the ftp folder?
I have found the way to get the list of filenames from the ftp folder.
Code:
#include "ftpwindow.h"
#include "ui_ftpwindow.h"
#include "qftp.h"
#include "qurl.h"
#include "QMessageBox"
#include "QFile"
FTPWindow
::FTPWindow(QWidget *parent
) : ui(new Ui::FTPWindow),ftp(0)
{
ui->setupUi(this);
QUrl url
("ftp.qt.nokia.com");
}
FTPWindow::~FTPWindow()
{
delete ui;
}
void FTPWindow
::changeEvent(QEvent *e
) {
switch (e->type()) {
ui->retranslateUi(this);
break;
default:
break;
}
}
void FTPWindow
::addToList(const QUrlInfo &urlInfo
) {
filelist += urlInfo.name();
//QMessageBox::information(this, tr("FTP"),filelist,QMessageBox::Ok);
QFile newfile
("ftpfilenames1.txt");
newfile.write(filelist.toAscii().data());
newfile.write("\r\n");
newfile.close();
}
void FTPWindow::on_Connect_clicked()
{
#ifdef Q_OS_SYMBIAN
if(!bDefaultIapSet) {
qt_SetDefaultIap();
bDefaultIapSet = true;
}
#endif
if (ftp) {
ftp->abort();
ftp->deleteLater();
ftp = 0;
//![0]
#ifndef QT_NO_CURSOR
setCursor(Qt::ArrowCursor);
#endif
return;
}
#ifndef QT_NO_CURSOR
setCursor(Qt::WaitCursor);
#endif
//![1]
connect(ftp, SIGNAL(commandFinished(int,bool)),
this, SLOT(ftpCommandFinished(int,bool)));
connect(ftp,
SIGNAL(listInfo
(QUrlInfo)),
QUrl url
("ftp.qt.nokia.com");
if (!url.
isValid() || url.
scheme().
toLower() != QLatin1String("ftp")) { ftp->connectToHost("ftp.qt.nokia.com", 21);
ftp->login();
} else {
ftp->connectToHost(url.host(), url.port(21));
if (!url.userName().isEmpty())
ftp
->login
(QUrl::fromPercentEncoding(url.
userName().
toLatin1()), url.
password());
else
ftp->login();
if (!url.path().isEmpty())
ftp->cd(url.path());
}
}
void FTPWindow::ftpCommandFinished(int, bool error)
{
#ifndef QT_NO_CURSOR
setCursor(Qt::ArrowCursor);
#endif
if (ftp
->currentCommand
() == QFtp::ConnectToHost) { if (error) {
tr("Unable to connect to the FTP server "
"at %1. Please check that the host "
"name is correct."),
on_Connect_clicked();
return;
}
return;
}
if (ftp
->currentCommand
() == QFtp::Login){ ftp->list(); }
else if (ftp
->currentCommand
() == QFtp::List) {
}
}
This creates a file ftpfilenames1.txt and it contains all the filenames from the ftp site. Works fine.
-
Re: How to connect to ftp server and read the filenames in the ftp folder?
I am getting all the lists including file and folder names. I just want to list only the filenames. How to filter in order to get the filenames alone?
-
Re: How to connect to ftp server and read the filenames in the ftp folder?
Have you looked at the docs for QUrlInfo, the class you are using to get the directory entry name, or did you just copy'n'paste from somewhere else?
-
Re: How to connect to ftp server and read the filenames in the ftp folder?
Thanks.. I have used isDir() and it worked... voilaaaaa
-
Re: How to connect to ftp server and read the filenames in the ftp folder?
Quote:
Originally Posted by
wysota
Hi Wysota,
i am having a small doubt. In the QT installed directory i found the example of "QFTP", which is used to connect to FTP Server.
Here my doubt is, can we connect to a remote machine by using an "host-name" of a remote system instead of "ftp.qt.nokia.com" in the same FTP example ?
-
Re: How to connect to ftp server and read the filenames in the ftp folder?
"ftp.qt.nokia.com" is a host name.
-
Re: How to connect to ftp server and read the filenames in the ftp folder?
yes i agree but i have given the ip address of the other machine in that ftp example i can able to connect it but cant see the files list.
My aim is to connect to a remote system (windows OS) from my Linux system and copy a directory of windows system (i.e., which consists of 2 or 3 text files) to my linux system.
-
Re: How to connect to ftp server and read the filenames in the ftp folder?
Quote:
Originally Posted by
mahi6a1985
yes i agree but i have given the ip address of the other machine in that ftp example i can able to connect it but cant see the files list.
Maybe it's a matter of being able to perform active/passive FTP connection.
-
Re: How to connect to ftp server and read the filenames in the ftp folder?
Quote:
Originally Posted by
wysota
Maybe it's a matter of being able to perform active/passive FTP connection.
yes you are absolutely correct my ftp server application which in windows wont accept passive FTP connection.
So, i have to make some changes then... ??
Thanks wysota
-
Re: How to connect to ftp server and read the filenames in the ftp folder?
You have to act accordingly to the protocol approach you wish to support.
-
Re: How to connect to ftp server and read the filenames in the ftp folder?
Quote:
Originally Posted by
wysota
You have to act accordingly to the protocol approach you wish to support.
Hi wysota,
Now i am able to connect to ftp server and can view the entire remote system FTP server files and also i can download them but the problem is some of them were 0-bytes means only file is downloaded non of the content is downloaded and some of them were half downloaded.
But all the files listed in the FTP site were downloaded to my local directory.
what could be the problem ?
i have seen the QFTP example their its only one file at a time so it seems fine. But in my case i want to download all the files of the ftp folder.
-
Re: How to connect to ftp server and read the filenames in the ftp folder?
And how are you doing that?
-
Re: How to connect to ftp server and read the filenames in the ftp folder?
Quote:
Originally Posted by
wysota
And how are you doing that?
After getting the list using ftp->list();
i am using a loop and calling each of the listed files one by one using ftp->get(urlInfo.name(),file);
-
Re: How to connect to ftp server and read the filenames in the ftp folder?
Show the actual code, please.
-
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.