Chris Haas's Blog

June 10, 2009

RegEx for parsing FTP LIST command

Filed under: Uncategorized — Tags: — chrishaas @ 8:22 am

Need to parse the FTP LIST command output? I did. Here’s what I came up with, its based on another post that didn’t quite work for me. The code below works specifically on the FilZilla FTP Server which I was targetting.


^(?<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{2})\s+(?<year>\d{4})))\s+(?<name>.+)$

Blog at WordPress.com.