Page 1 of 2 12 LastLast
Results 1 to 20 of 30

Thread: How to check the file to download from ftp site exists ?

  1. #1
    Join Date
    Jan 2008
    Location
    Bengaluru
    Posts
    144
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default How to check the file to download from ftp site exists ?

    Hi,

    I need to check whether the file to download from the given ftp site exists. Is there any method where I can use to check whether the file exists before initiating the download using QFTP:get(...).

    Thanks in advance.

  2. #2
    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 check the file to download from ftp site exists ?

    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
    Jan 2008
    Location
    Bengaluru
    Posts
    144
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: How to check the file to download from ftp site exists ?

    Thanks for the immediate response. It means I need to use non-Qt APIs to check for the file existence? Are theren't any Qt APIs to check for the file existence.

    Thanks for your help.

  4. #4
    Join Date
    Dec 2010
    Location
    Russia
    Posts
    83
    Thanks
    1
    Thanked 12 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to check the file to download from ftp site exists ?

    int QFtp::list ( const QString & dir = QString() )

    Lists the contents of directory dir on the FTP server. If dir is empty, it lists the contents of the current directory.

    The listInfo() signal is emitted for each directory entry found.
    void QFtp::listInfo ( const QUrlInfo & i ) [signal]

    This signal is emitted for each directory entry the list() command finds. The details of the entry are stored in i.
    and the last one ^^:
    QString QUrlInfo::name () const

    Returns the file name of the URL.

  5. #5
    Join Date
    Jan 2008
    Location
    Bengaluru
    Posts
    144
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: How to check the file to download from ftp site exists ?

    I am actually using this method for retrieving the list. But this is kind of work around to check whether file exists. Because every time I need to do QFtp::cd(...) and get the list and then check whether the file exists. I was actually looking for any straight forward APIs where I need to login with my credentials to ftp site and check whether the file I need exists or not. As I was searching some of the other languages support it. So I was curious whether Qt has it. Thanks for your help.

    Please let me know if there is any direct APIs whether in Qt or C++. Thanks.

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to check the file to download from ftp site exists ?

    It means I need to use non-Qt APIs to check for the file existence?
    No, it doesn't mean that. It means that the question is asked routinely all across the 'net, using various libraries and languages, and the approach to the problem is generally the same. Either:
    • Try to download the file, if it works the file exists...
    • Issue an FTP "ls filename" command and see if the file name is present in the output.


    The QFtp class has a function to do both of those things.
    Only the first option is available using QNetworkAccessManager AFAICT, but you could abort() the download as soon as you see the metadataChanged() signal.

  7. #7
    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 check the file to download from ftp site exists ?

    Quote Originally Posted by ChrisW67 View Post
    Only the first option is available using QNetworkAccessManager AFAICT, but you could abort() the download as soon as you see the metadataChanged() signal.
    There is QFtp::list() available (since OP is using QFtp anyway).
    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.


  8. #8
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to check the file to download from ftp site exists ?

    There you go pointing the OP straight at it ... I was trying to be more subtle by saying that QFtp had functions for both and that some RTFM action might be needed.

  9. #9
    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 check the file to download from ftp site exists ?

    Ouch, sorry.. didn't read your post carefully enough... Still one has to read the docs to learn how to process the response QFtp receives.
    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.


  10. #10
    Join Date
    Jan 2008
    Location
    Bengaluru
    Posts
    144
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: How to check the file to download from ftp site exists ?

    Quote Originally Posted by ChrisW67 View Post
    There you go pointing the OP straight at it ... I was trying to be more subtle by saying that QFtp had functions for both and that some RTFM action might be needed.
    Could you please expand OP and RTFM and please let me know how to interpret it. Thanks.


    Added after 5 minutes:


    While fetching the data I am using QFtp::get and if the operation returned 'error' true for QFtp::CommandFinished(int, bool error) then the rest of QFtp commands are not executing. Since all the ftp commands are asynchronous, if one of the command fails does the remaining rest following them aborts ?, because my program does not do anything if any one of the ftp command returns 'error'.
    Last edited by nikhilqt; 16th February 2012 at 22:24.

  11. #11
    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 check the file to download from ftp site exists ?

    Quote Originally Posted by nikhilqt View Post
    Could you please expand OP and RTFM and please let me know how to interpret it.
    OP is "original poster" (meaning you). RTFM is... well... STFW for it

    The Jargon File
    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.


  12. #12
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to check the file to download from ftp site exists ?

    Quote Originally Posted by nikhilqt View Post
    While fetching the data I am using QFtp::get and if the operation returned 'error' true for QFtp::CommandFinished(int, bool error) then the rest of QFtp commands are not executing. Since all the ftp commands are asynchronous, if one of the command fails does the remaining rest following them aborts ?, because my program does not do anything if any one of the ftp command returns 'error'.
    From the friendly manual for QFtp (you have read it, haven't you? )...
    If an error occurs during the execution of one of the commands in a sequence of commands, all the pending commands (i.e. scheduled, but not yet executed commands) are cleared and no signals are emitted for them.

  13. #13
    Join Date
    Jan 2008
    Location
    Bengaluru
    Posts
    144
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: How to check the file to download from ftp site exists ?

    Quote Originally Posted by ChrisW67 View Post
    From the friendly manual for QFtp (you have read it, haven't you? )...
    Oh! it is there in the documentation . I didn't see it hard enough. So now it creates a issue for me for even 'ls filename' command, because the remaining QFtp::get(...) requests would be lost since the former command fails if the file is not present.

  14. #14
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to check the file to download from ftp site exists ?

    Why? If the list command fails there is no file to download. If you a queuing several file list/get commands at once, don't.

    I expect the list command will not fail if the file does not exist: it should just return no directory entries. (I have not verified that)

  15. The following user says thank you to ChrisW67 for this useful post:

    nikhilqt (27th February 2012)

  16. #15
    Join Date
    Jan 2008
    Location
    Bengaluru
    Posts
    144
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: How to check the file to download from ftp site exists ?

    Quote Originally Posted by ChrisW67 View Post
    I expect the list command will not fail if the file does not exist: it should just return no directory entries. (I have not verified that)
    But my requirement is to check whether that specific file exists or not in that folder. I cannot achieve it using list command. So as you said I used 'ls filename'.

    Why? If the list command fails there is no file to download. If you a queuing several file list/get commands at once, don't.
    There are some 40-50 files I need to download and this number might increase as well. So I queue up the request of all the raw command('ls filename') for all the files.

    My approach was to check the error status of all the raw commands and then selectively call the QFtp::get method only for those files which exists. But here the checking queue is itself failing for me.

  17. #16
    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 check the file to download from ftp site exists ?

    Quote Originally Posted by nikhilqt View Post
    But my requirement is to check whether that specific file exists or not in that folder. I cannot achieve it using list command.
    Why not?


    There are some 40-50 files I need to download and this number might increase as well. So I queue up the request of all the raw command('ls filename') for all the files.
    Don't do that then. Store the file data elsewhere and push commands to the ftp client as you begin processing a particular entry.
    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.


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

    nikhilqt (27th February 2012)

  19. #17
    Join Date
    Jan 2008
    Location
    Bengaluru
    Posts
    144
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: How to check the file to download from ftp site exists ?

    Thanks. I made it work. In the process, I observed one more situation, where the QFtp::Get command will be running and there won't be write to the file in the local file system. This happens quite a sometime after the download of some 20-30 files. Is this because ftp has timeout and the state is been disconnected ?

    If I close the application and start it again, then the downloading starts normally. Have anybody experienced this behavior ?
    Last edited by nikhilqt; 27th February 2012 at 21:09.

  20. #18
    Join Date
    Jan 2008
    Location
    Bengaluru
    Posts
    144
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: How to check the file to download from ftp site exists ?

    Guys, Any help regarding this. Is there any timeout for the QFtp::Get command. Or do i need to close the ftp connection after sometime and need to re-initiate it ? Please share me your thoughts on it. Thanks

  21. #19
    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 check the file to download from ftp site exists ?

    I think you are adressing the question in the wrong place. If you want to learn how FTP servers work, then learn about FTP. Qt has nothing to do with this. Your "issue" is stricly FTP related from the very beginning.
    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.


  22. #20
    Join Date
    Jan 2008
    Location
    Bengaluru
    Posts
    144
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: How to check the file to download from ftp site exists ?

    Quote Originally Posted by wysota View Post
    I think you are adressing the question in the wrong place. If you want to learn how FTP servers work, then learn about FTP. Qt has nothing to do with this. Your "issue" is stricly FTP related from the very beginning.
    I checked FTP is working fine. The connection is up and running. I figured out the situation when it stops downloading. I have QTimer setup, which is running in a different thread, when it fires a 'timeout' signal(While QFtp::Get is in progress) the download stops.

    Is this because of the thread affinity. Do I need to call moveToThread(..) to initiate the main thread event loop ? Please comment.

    Thanks.
    Last edited by nikhilqt; 28th February 2012 at 23:13.

Similar Threads

  1. How to check Primary key is Exists in Table ?
    By hohoanganh205 in forum Newbie
    Replies: 4
    Last Post: 28th December 2011, 08:54
  2. Replies: 2
    Last Post: 21st February 2011, 15:52
  3. Check if item exists into listwidget
    By hakermania in forum Qt Programming
    Replies: 1
    Last Post: 26th January 2011, 22:54
  4. Check if a table exists in a mysql database
    By graciano in forum Qt Programming
    Replies: 8
    Last Post: 5th November 2009, 03:44
  5. Check if window with certain title exists
    By devil in forum Qt Programming
    Replies: 5
    Last Post: 21st January 2009, 15:42

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.