Analysis of the response from the FTP LIST command (syntax options)

The FTP LIST command displays a list of all files and directories in the current working directory. The problem is that it returns several different formats depending on the server. Does anyone know a .NET library that can parse the most popular formats? I'm fine with "try this regex, if it doesn't work, try using the following regex".

+4
source share
4 answers

Here is the one I used for the 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/

+8
source

This uses RegEx, which I used in the project. It seems to work for both Windows FTP servers and Unix. Someone can clear it, but I create it by combining a bunch of properties in the class. Therefore, itโ€™s not so cruel to support 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,}))$ 
+4
source
 ^(?<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 version of Chris Haas a bit. Changed so that the day grouping can consist of one number. \ d {2} โ†’ \ d {1,2}

Thanks for the original version.

+1
source
 ^(?<dir>[\-ld])(?<permission>([\-r][\-w][\-xs]){3})\s+(?<filecode>\d+)\s+(?<owner>\S+)\s+(?<group>\S+)\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>.+)$ 

On the site Iโ€™m on, the owner is displayed in the format of an email address. I changed the owner and group to non-spatial characters instead of word characters.

This extends the version of Chris Haas's "Iodide" version. Thanks!

0
source

Source: https://habr.com/ru/post/1285925/


All Articles