Results 1 to 20 of 30

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

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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 21: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)

Similar Threads

  1. How to check Primary key is Exists in Table ?
    By hohoanganh205 in forum Newbie
    Replies: 4
    Last Post: 28th December 2011, 07:54
  2. Replies: 2
    Last Post: 21st February 2011, 14:52
  3. Check if item exists into listwidget
    By hakermania in forum Qt Programming
    Replies: 1
    Last Post: 26th January 2011, 21:54
  4. Check if a table exists in a mysql database
    By graciano in forum Qt Programming
    Replies: 8
    Last Post: 5th November 2009, 02:44
  5. Check if window with certain title exists
    By devil in forum Qt Programming
    Replies: 5
    Last Post: 21st January 2009, 14: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.