FTP listing problem to detect folders

Bringing the internet highway into your project? Building FTP, HTTP, email, chat or other client solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
paulclaude
Posts: 121
Joined: Thu Mar 27, 2008 10:19 am

FTP listing problem to detect folders

Post by paulclaude » Thu Apr 29, 2010 4:50 pm

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

Curry
Posts: 111
Joined: Mon Oct 15, 2007 11:34 pm
Contact:

Re: FTP listing problem to detect folders

Post by Curry » Thu Apr 29, 2010 5:59 pm

Looks like:

put "<DIR>" is in tLine into isFolder
Best wishes,

Curry Kenworthy

LiveCode Development, Training & Consulting
http://livecodeconsulting.com/

WordLib: Conquer MS Word & OpenOffice
SpreadLib: "Excel-lent" spreadsheet import/export
http://livecodeaddons.com/

paulclaude
Posts: 121
Joined: Thu Mar 27, 2008 10:19 am

Re: FTP listing problem to detect folders

Post by paulclaude » Thu Apr 29, 2010 6:22 pm

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

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: FTP listing problem to detect folders

Post by mwieder » Thu Apr 29, 2010 6:51 pm

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.

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: FTP listing problem to detect folders

Post by bangkok » Thu Apr 29, 2010 9:43 pm

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 ?

paulclaude
Posts: 121
Joined: Thu Mar 27, 2008 10:19 am

Re: FTP listing problem to detect folders

Post by paulclaude » Fri Apr 30, 2010 8:16 am

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

paulclaude
Posts: 121
Joined: Thu Mar 27, 2008 10:19 am

Re: FTP listing problem to detect folders

Post by paulclaude » Thu May 06, 2010 11:16 am

Bump!

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

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: FTP listing problem to detect folders

Post by mwieder » Thu May 06, 2010 10:13 pm

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?

paulclaude
Posts: 121
Joined: Thu Mar 27, 2008 10:19 am

Re: FTP listing problem to detect folders

Post by paulclaude » Fri May 07, 2010 8:31 am

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.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: FTP listing problem to detect folders

Post by FourthWorld » Fri May 07, 2010 1:50 pm

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

paulclaude
Posts: 121
Joined: Thu Mar 27, 2008 10:19 am

Re: FTP listing problem to detect folders

Post by paulclaude » Fri May 07, 2010 2:59 pm

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

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: FTP listing problem to detect folders

Post by FourthWorld » Fri May 07, 2010 4:10 pm

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?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

paulclaude
Posts: 121
Joined: Thu Mar 27, 2008 10:19 am

Re: FTP listing problem to detect folders

Post by paulclaude » Fri May 07, 2010 5:14 pm

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.

Post Reply