Results 1 to 20 of 28

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

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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?

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 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?

    Quote Originally Posted by mahi6a1985 View Post
    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.
    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. #3
    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
    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

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 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 have to act accordingly to the protocol approach you wish to support.
    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.


  5. #5
    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 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.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 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 how are you doing that?
    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.


  7. #7
    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
    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);

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 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?

    Show the actual code, please.
    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.


  9. #9
    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 

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 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.


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

    mahi6a1985 (18th December 2012)

  12. #11
    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

  13. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 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.


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
  •  
Qt is a trademark of The Qt Company.