Page 1 of 1

FTP listing problem to detect folders

Posted: Thu Apr 29, 2010 4:50 pm
by paulclaude
I used to display an FTP directory as usual, with

Code: Select all

 libURLSetFTPListCommand "LIST"
put URL myURL into temp
and having something like this as result:

Code: Select all

drwxr-x---   3 dave  staff   102 Mar 29  2003 liburltestaxx
-rwxr--r--   1 dave  staff   981 Apr  8  2002 urlconfig.mc 
where I can detect directories by the first char of each line (d=directory).

Now I've found a result like this:

Code: Select all

08-24-09  01:44PM       <DIR>          _private
08-24-09  01:44PM                 1754 _vti_inf.html
08-24-09  01:44PM       <DIR>          _vti_log
08-24-09  01:44PM       <DIR>          App_Data
I don't know this format: how can I detect it to correctly to identify files and folders?

Thanks

Paul

Re: FTP listing problem to detect folders

Posted: Thu Apr 29, 2010 5:59 pm
by Curry
Looks like:

put "<DIR>" is in tLine into isFolder

Re: FTP listing problem to detect folders

Posted: Thu Apr 29, 2010 6:22 pm
by paulclaude
Curry wrote:Looks like:

put "<DIR>" is in tLine into isFolder
Thank you, Curry, but this was not the real problem, I know quite well how to detect "<DIR>" in a string. The problem is that I don't know:
  • 1. How many kinds of FTP answers to directory listing I can expect
    2. If I can "question" the FTP to pre-emptively know what kind of form will have this answer

Re: FTP listing problem to detect folders

Posted: Thu Apr 29, 2010 6:51 pm
by mwieder
1. How many kinds of FTP answers to directory listing I can expect
As many as there are different types of ftp servers. As soon as you make a complete list, another one will appear. RFC 959 at http://tools.ietf.org/html/rfc959 specifies the ftp commands but not the response format, leaving this wide open. The commentary in RFC 1123 http://www.freesoft.org/CIE/RFC/1123/53.htm (see the discussion in section 4.1) seems even vaguer.

Re: FTP listing problem to detect folders

Posted: Thu Apr 29, 2010 9:43 pm
by bangkok
There might be another solution.

Test the name on each line...

if it contains "." with an extension, then it's likely to be a file, if it doesn't, then it's likely to be a directory.

No ?

Re: FTP listing problem to detect folders

Posted: Fri Apr 30, 2010 8:16 am
by paulclaude
bangkok wrote:There might be another solution.

Test the name on each line...

if it contains "." with an extension, then it's likely to be a file, if it doesn't, then it's likely to be a directory.

No ?
This could be a good raw method, but if I can't know the FTP list format, how can I detect the position of a file name? And the file size (I need it too)?

I wonder if it is possible that nobody, listing FTP servers, has met (and tried to solve) the same problem?

Please help...

Re: FTP listing problem to detect folders

Posted: Thu May 06, 2010 11:16 am
by paulclaude
Bump!

Is There Anybody Out There (thanks Pink Floyd..)? :(

Re: FTP listing problem to detect folders

Posted: Thu May 06, 2010 10:13 pm
by mwieder
Are you still looking for a generic solution that will work will *all* ftp servers even though there's no specification for the format they should return?

Re: FTP listing problem to detect folders

Posted: Fri May 07, 2010 8:31 am
by paulclaude
mwieder wrote:Are you still looking for a generic solution that will work will *all* ftp servers even though there's no specification for the format they should return?
I'm only looking for somebody who has faced the problem before me, to have some idea, maybe to detect and "decode" (extract file names and sizes) the more common FTP formats. Be sure, I don't search for someone to "do the job" for me: I search for some developer (if exists) that already came into this problem before and like to share some hint.

Re: FTP listing problem to detect folders

Posted: Fri May 07, 2010 1:50 pm
by FourthWorld
This may not be much help, but when faced with a similar issue I opted to take a completely different route, bypassing FTP altogether and using a CGI instead. With a CGI I can use things like "the detailed files" and "the folders" to get all sorts of info in a common format that makes it easy to work with.

Re: FTP listing problem to detect folders

Posted: Fri May 07, 2010 2:59 pm
by paulclaude
FourthWorld wrote:This may not be much help, but when faced with a similar issue I opted to take a completely different route, bypassing FTP altogether and using a CGI instead. With a CGI I can use things like "the detailed files" and "the folders" to get all sorts of info in a common format that makes it easy to work with.
Thank you, Richard, unfortunately I don't know at all CGI scripting (but it seems to me that, to use a CGI script, the client must have CGI access on the host / server and I don't know the users servers).

Re: FTP listing problem to detect folders

Posted: Fri May 07, 2010 4:10 pm
by FourthWorld
Another option might be to write the hosting company and ask if there's a way to get FTP listings in the RFC-recommended format. It's a long shot that they'll comply, but maybe worth a shot. FWIW, I've seen some oddities in FTP listings, but none quite like the example you posted. It would be interesting to know if any third-party FTP tool deals with it well. Have you tired Filezilla?

Re: FTP listing problem to detect folders

Posted: Fri May 07, 2010 5:14 pm
by paulclaude
FourthWorld wrote:Another option might be to write the hosting company and ask if there's a way to get FTP listings in the RFC-recommended format. It's a long shot that they'll comply, but maybe worth a shot. FWIW, I've seen some oddities in FTP listings, but none quite like the example you posted. It would be interesting to know if any third-party FTP tool deals with it well. Have you tired Filezilla?
I've tried Cyberduck, and it deals with those sites. Since I did a program that also offer a basic FTP support, I need a solution applicable to any user of my software and their FTP servers. BTW, for the moment I will play with the posted examples, that are easy to detect, hoping not to find too many other FTP listing oddities. Thanks for your help.