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.
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.
Sure, look here: How to check if FTP file 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.
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.and the last one ^^: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.
QString QUrlInfo::name () const
Returns the file name of the URL.
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.
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:It means I need to use non-Qt APIs to check for the file existence?
- 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.
There is QFtp::list() available (since OP is using QFtp anyway).
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.
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.
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.
OP is "original poster" (meaning you). RTFM is... well... STFW for it
The Jargon File
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.
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.
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)
nikhilqt (27th February 2012)
Bookmarks