Page 2 of 2 FirstFirst 12
Results 21 to 28 of 28

Thread: How to connect to ftp server and read the filenames in the ftp folder?

  1. #21
    Join Date
    Sep 2012
    Posts
    32
    Thanks
    18
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to connect to ftp server and read the filenames in the ftp folder?

    Quote Originally Posted by wysota View Post
    Show the actual code, please.
    Qt Code:
    1. localDir = "/home/nn";
    2. QUrl url("ftp://192.168.1.146");
    3. ftp->connectToHost(url.host(),url.port(21));
    4. ftp->login();
    5. connect(ftp, SIGNAL(commandFinished(int,bool)), this, SLOT(ftpCommandFinished(int,bool)));
    6. connect(ftp, SIGNAL(listInfo(QUrlInfo)), this, SLOT(ftpListInfo(QUrlInfo)));
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. void MainWindow::ftpCommandFinished(int, bool error)
    2. {
    3. if(ftp->currentCommand() == QFtp::ConnectToHost)
    4. {
    5. ftp->login();
    6. }
    7.  
    8. if(ftp->currentCommand() == QFtp::Login)
    9. {
    10. ftp->list();
    11. }
    12.  
    13. if(ftp->currentCommand() == QFtp::Get)
    14. {
    15. file->close();
    16. }
    17.  
    18. if(ftp->currentCommand() == QFtp::List)
    19. {
    20. download(listF);
    21. }
    22. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. void MainWindow::ftpListInfo(QUrlInfo urlInfo)
    2. {
    3. if(urlInfo.isFile() && urlInfo.isReadable())
    4. {
    5. listF.append(urlInfo);
    6. }
    7. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. void MainWindow::download(QList<QUrlInfo> listF)
    2. {
    3. foreach(QUrlInfo urlInfo, listF)
    4. if(urlInfo.isFile() && urlInfo.isReadable())
    5. {
    6. file = new QFile(localDir + "/" + urlInfo.name());
    7. file->open(QIODevice::WriteOnly);
    8. ftp->get(urlInfo.name(), file);
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 

  2. #22
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    mahi6a1985 (18th December 2012)

  4. #23
    Join Date
    Sep 2012
    Posts
    32
    Thanks
    18
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to connect to ftp server and read the filenames in the ftp folder?

    Quote Originally Posted by wysota View Post
    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

  5. #24
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to connect to ftp server and read the filenames in the ftp folder?

    Your code is wrong. Period.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #25
    Join Date
    Sep 2012
    Posts
    32
    Thanks
    18
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to connect to ftp server and read the filenames in the ftp folder?

    Quote Originally Posted by wysota View Post
    Your code is wrong. Period.
    I got it... the problem solved.

  7. #26
    Join Date
    Sep 2012
    Posts
    32
    Thanks
    18
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

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

    ./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.
    Last edited by mahi6a1985; 24th December 2012 at 08:19.

  8. #27
    Join Date
    Sep 2012
    Posts
    32
    Thanks
    18
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

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

  9. #28
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Connect To Sql Server With QT
    By METEOR7 in forum Qt Programming
    Replies: 6
    Last Post: 13th December 2011, 12:39
  2. Trying to Connect To SQL Server 2005
    By rossd in forum Installation and Deployment
    Replies: 0
    Last Post: 6th March 2009, 19:56
  3. QFtp: downloading a whole folder from a remote server.
    By balazsbela in forum Qt Programming
    Replies: 5
    Last Post: 5th August 2007, 09:34
  4. cannot connect to X server
    By jcr in forum Qt Programming
    Replies: 1
    Last Post: 18th April 2007, 14:22
  5. connect to sql server
    By raphaelf in forum Qt Programming
    Replies: 15
    Last Post: 27th February 2006, 18:06

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.