The FTP LIST command displays a listing of all the files and directories in the current working directory. The problem is, it returns several different formats depending on the server. Does anybody know of a .NET library that is able to parse the most popular formats? I am OK with a "try this regex, if it fails, try the next regex" approach.
A:
If you are talking to the FTP server with the FtpWebRequest & FtpWebResponse classes, they may be what you need.
Austin Salonen
2009-06-08 20:31:07
+1
A:
Here is a RegEx I used on a project. Seems to work for both Windows and Unix based FTP servers. Someone might be able to clean it up but I build it by concatenating a bunch of properties on a class. So it's not as brutal to maintain for me.
^((?<DIR>([dD]{1}))|)(?<ATTRIBS>(.*))\s(?<SIZE>([0-9]{1,}))\s(?<DATE>((?<MONTHDAY>((?<MONTH>(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec))\s(?<DAY>([0-9\s]{2}))))\s(\s(?<YEAR>([0-9]{4}))|(?<TIME>([0-9]{2}\:[0-9]{2})))))\s(?<NAME>([A-Za-z0-9\-\._\s]{1,}))$
Matthew Whited
2009-06-08 20:37:45
+3
A:
Here's the one that I've been using for a FileZilla server:
^(?<dir>[\-ld])(?<permission>([\-r][\-w][\-xs]){3})\s+(?<filecode>\d+)\s+(?<owner>\w+)\s+(?<group>\w+)\s+(?<size>\d+)\s+(?<timestamp>((?<month>\w{3})\s+(?<day>\d{2})\s+(?<hour>\d{1,2}):(?<minute>\d{2}))|((?<month>\w{3})\s+(?<day>\d{1,2})\s+(?<year>\d{4})))\s+(?<name>.+)$
http://chrishaas.wordpress.com/2009/06/10/regex-for-parsing-ftp-list-command/
Thank you very much!
Josh Stodola
2009-06-25 18:54:35
+1
A:
^(?<dir>[\-ld])(?<permission>([\-r][\-w][\-xs]){3})\s+(?<filecode>\d+)\s+(?<owner>\w+)\s+(?<group>\w+)\s+(?<size>\d+)\s+(?<timestamp>((?<month>\w{3})\s+(?<day>\d{1,2})\s+(?<hour>\d{1,2}):(?<minute>\d{2}))|((?<month>\w{3})\s+(?<day>\d{1,2})\s+(?<year>\d{4})))\s+(?<name>.+)$
Changed Chris Haas version a tiny little bit. Changed so that the day grouping can consist of a single number as well. \d{2} -> \d{1,2}
Thanks for original version.
Yodiz
2010-02-01 12:57:17
Thanks for the update! I updated Chris' answer to include this change.
Josh Stodola
2010-02-01 14:14:28