Parse response from FTP LIST command (syntax variations)

后端 未结 4 1696
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-06 07:16

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

相关标签:
4条回答
  • 2021-01-06 07:27
    ^(?<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.

    0 讨论(0)
  • 2021-01-06 07:37

    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/

    0 讨论(0)
  • 2021-01-06 07:44

    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,}))$
    
    0 讨论(0)
  • 2021-01-06 07:54
    ^(?<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 Email address format. I changed owner and group to be non-space characters instead of word characters.

    This is expanding on Yodiz' version of Chris Haas' version. Thanks so much!

    0 讨论(0)
提交回复
热议问题