<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Sample code for parsing FtpwebRequest response for ListDirectoryDetails</title><link>http://blogs.msdn.com/adarshk/archive/2004/09/15/sample-code-for-parsing-ftpwebrequest-response-for-listdirectorydetails.aspx</link><description>This posting is valid for .Net frameworks 2.0 (Currently released as Whidbey Beta1) ResponseStream of FtpWebResponse provides the raw data bytes to the user, s ome of you had asked that it would be more useful to provide methods which return list of directory</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>FtpwebRequest response for ListDirectoryDetails</title><link>http://blogs.msdn.com/adarshk/archive/2004/09/15/sample-code-for-parsing-ftpwebrequest-response-for-listdirectorydetails.aspx#1046057</link><pubDate>Thu, 09 Nov 2006 23:31:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1046057</guid><dc:creator>Sim</dc:creator><description>&lt;p&gt;Getting the following error while doing this:&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;using (FtpWebResponse response = (FtpWebResponse)ftp.GetResponse())&lt;/p&gt;
&lt;p&gt;The Remote Server returned an error:(550) File unavailable(e.g., file not found, no access)&lt;/p&gt;
</description></item><item><title>Some corrections</title><link>http://blogs.msdn.com/adarshk/archive/2004/09/15/sample-code-for-parsing-ftpwebrequest-response-for-listdirectorydetails.aspx#2478607</link><pubDate>Tue, 08 May 2007 15:38:55 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2478607</guid><dc:creator>Steffen Xavier xsteffen@ict7.com</dc:creator><description>&lt;P&gt;Replace:&lt;/P&gt;
&lt;P&gt;string[] strs = processstr.Split(new char[] { ' ' }, true);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; processstr = strs[1];&lt;/P&gt;
&lt;P&gt;By:&lt;/P&gt;
&lt;P&gt;processstr = processstr.Remove(0,processstr.IndexOf(' ') + 1);&lt;/P&gt;
&lt;P&gt;Otherwise you truncate file name with white spaces.&lt;/P&gt;
&lt;P&gt;f.CreateTime = DateTime.Parse(dateStr + " " + timeStr); Can throw a InvalidFormatException. Replace by&lt;/P&gt;
&lt;P&gt;f.CreateTime = DateTime.Parse(dateStr + " " + timeStr, CultureInfo.GetCultureInfo("en-US"));&lt;/P&gt;
&lt;P&gt;Thanks for you code. He help me.&lt;/P&gt;</description></item><item><title>re: Sample code for parsing FtpwebRequest response for ListDirectoryDetails</title><link>http://blogs.msdn.com/adarshk/archive/2004/09/15/sample-code-for-parsing-ftpwebrequest-response-for-listdirectorydetails.aspx#3379377</link><pubDate>Mon, 18 Jun 2007 12:06:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3379377</guid><dc:creator>Atam</dc:creator><description>&lt;p&gt;Thanks, saved me some time reverse engineering the crap out of this streamreader:)&lt;/p&gt;
</description></item><item><title>re: Sample code for parsing FtpwebRequest response for ListDirectoryDetails</title><link>http://blogs.msdn.com/adarshk/archive/2004/09/15/sample-code-for-parsing-ftpwebrequest-response-for-listdirectorydetails.aspx#5116860</link><pubDate>Tue, 25 Sep 2007 12:22:15 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5116860</guid><dc:creator>DeMi</dc:creator><description>&lt;p&gt;Hay,&lt;/p&gt;
&lt;p&gt;Here some code using Regular Expressions which makes life a little easier (besides making the regular expression ;-)&lt;/p&gt;
&lt;p&gt;public class FTPLineParser&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;	private Regex unixStyle = new Regex(@&amp;quot;^(?&amp;lt;dir&amp;gt;[-dl])(?&amp;lt;ownerSec&amp;gt;[-r][-w][-x])(?&amp;lt;groupSec&amp;gt;[-r][-w][-x])(?&amp;lt;everyoneSec&amp;gt;[-r][-w][-x])\s+(?:\d)\s+(?&amp;lt;owner&amp;gt;\w+)\s+(?&amp;lt;group&amp;gt;\w+)\s+(?&amp;lt;size&amp;gt;\d+)\s+(?&amp;lt;month&amp;gt;\w+)\s+(?&amp;lt;day&amp;gt;\d{1,2})\s+(?&amp;lt;hour&amp;gt;\d{1,2}):(?&amp;lt;minutes&amp;gt;\d{1,2})\s+(?&amp;lt;name&amp;gt;.*)$&amp;quot;);&lt;/p&gt;
&lt;p&gt;	private Regex winStyle = new Regex(@&amp;quot;^(?&amp;lt;month&amp;gt;\d{1,2})-(?&amp;lt;day&amp;gt;\d{1,2})-(?&amp;lt;year&amp;gt;\d{1,2})\s+(?&amp;lt;hour&amp;gt;\d{1,2}):(?&amp;lt;minutes&amp;gt;\d{1,2})(?&amp;lt;ampm&amp;gt;am|pm)\s+(?&amp;lt;dir&amp;gt;[&amp;lt;]dir[&amp;gt;])?\s+(?&amp;lt;size&amp;gt;\d+)?\s+(?&amp;lt;name&amp;gt;.*)$&amp;quot;);&lt;/p&gt;
&lt;p&gt;	public FTPLineResult Parse(string line)&lt;/p&gt;
&lt;p&gt;	{&lt;/p&gt;
&lt;p&gt;		Match match = unixStyle.Match(line);&lt;/p&gt;
&lt;p&gt;		if (match.Success)&lt;/p&gt;
&lt;p&gt;		{&lt;/p&gt;
&lt;p&gt;			return ParseMatch(match.Groups, ListStyle.Unix);&lt;/p&gt;
&lt;p&gt;		}&lt;/p&gt;
&lt;p&gt;		match = winStyle.Match(line);&lt;/p&gt;
&lt;p&gt;		if (match.Success)&lt;/p&gt;
&lt;p&gt;		{&lt;/p&gt;
&lt;p&gt;			return ParseMatch(match.Groups, ListStyle.Unix);&lt;/p&gt;
&lt;p&gt;		}&lt;/p&gt;
&lt;p&gt;		throw new Exception(&amp;quot;Invalid line format&amp;quot;);&lt;/p&gt;
&lt;p&gt;	}&lt;/p&gt;
&lt;p&gt;	private FTPLineResult ParseMatch(GroupCollection matchGroups, ListStyle style)&lt;/p&gt;
&lt;p&gt;	{&lt;/p&gt;
&lt;p&gt;		string dirMatch = (style == ListStyle.Unix ? &amp;quot;d&amp;quot; : &amp;quot;&amp;lt;dir&amp;gt;&amp;quot;);&lt;/p&gt;
&lt;p&gt;		FTPLineResult result = new FTPLineResult();&lt;/p&gt;
&lt;p&gt;		result.Style = style;&lt;/p&gt;
&lt;p&gt;		result.IsDirectory = matchGroups[&amp;quot;dir&amp;quot;].Value.Equals(dirMatch, StringComparison.InvariantCultureIgnoreCase);&lt;/p&gt;
&lt;p&gt;		result.Name = matchGroups[&amp;quot;name&amp;quot;].Value;&lt;/p&gt;
&lt;p&gt;		if (!result.IsDirectory)&lt;/p&gt;
&lt;p&gt;			result.Size = long.Parse(matchGroups[&amp;quot;size&amp;quot;].Value);&lt;/p&gt;
&lt;p&gt;		return result;&lt;/p&gt;
&lt;p&gt;	}&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;public enum ListStyle&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;	Unix,&lt;/p&gt;
&lt;p&gt;	Windows&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;public class FTPLineResult&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;	public ListStyle Style;&lt;/p&gt;
&lt;p&gt;	public string Name;&lt;/p&gt;
&lt;p&gt;	public DateTime DateTime;&lt;/p&gt;
&lt;p&gt;	public bool IsDirectory;&lt;/p&gt;
&lt;p&gt;	public long Size;&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
</description></item><item><title>re: Sample code for parsing FtpwebRequest response for ListDirectoryDetails</title><link>http://blogs.msdn.com/adarshk/archive/2004/09/15/sample-code-for-parsing-ftpwebrequest-response-for-listdirectorydetails.aspx#5117039</link><pubDate>Tue, 25 Sep 2007 12:35:51 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5117039</guid><dc:creator>DeMi</dc:creator><description>&lt;p&gt;Hay, DeMi again.&lt;/p&gt;
&lt;p&gt;I hit the &amp;lt;ENTER&amp;gt; to quick when adding my example :-O&lt;/p&gt;
&lt;p&gt;Some details:&lt;/p&gt;
&lt;p&gt;In my previous example its better to use the RegexOptions.IgnoreCase option in the RegEx constructor.&lt;/p&gt;
&lt;p&gt;private Regex unixStyle = new Regex(@&amp;quot;^...$&amp;quot;, RegexOptions.IgnoreCase);&lt;/p&gt;
&lt;p&gt;private Regex winStyle = new Regex(@&amp;quot;^...$&amp;quot;, RegexOptions.IgnoreCase);&lt;/p&gt;
&lt;p&gt;To call the FTPLineParser you can use the code below:&lt;/p&gt;
&lt;p&gt;//...&lt;/p&gt;
&lt;p&gt;FtpWebResponse ftpResponse = (FtpWebResponse) ftpRequest.GetResponse();&lt;/p&gt;
&lt;p&gt;Stream response = ftpResponse.GetResponseStream();&lt;/p&gt;
&lt;p&gt;StreamReader responseReader = new StreamReader(response);&lt;/p&gt;
&lt;p&gt;string line = null;&lt;/p&gt;
&lt;p&gt;FTPLineParser parser = new FTPLineParser();&lt;/p&gt;
&lt;p&gt;List&amp;lt;FTPLineResult&amp;gt; lines = new List&amp;lt;FTPLineResult&amp;gt;();&lt;/p&gt;
&lt;p&gt;while ((line = responseReader.ReadLine()) != null)&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;	FTPLineResult lineResult = parser.Parse(line);&lt;/p&gt;
&lt;p&gt;	lines.Add(lineResult);&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;DoSomethingWithTheParsedLines(lines);&lt;/p&gt;
&lt;p&gt;Hope this is of some help for you.&lt;/p&gt;
&lt;p&gt;Enjoy.&lt;/p&gt;
&lt;p&gt;Dennis&lt;/p&gt;
</description></item><item><title>re: Sample code for parsing FtpwebRequest response for ListDirectoryDetails</title><link>http://blogs.msdn.com/adarshk/archive/2004/09/15/sample-code-for-parsing-ftpwebrequest-response-for-listdirectorydetails.aspx#8464775</link><pubDate>Wed, 07 May 2008 07:31:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8464775</guid><dc:creator>Bomzhang</dc:creator><description>&lt;p&gt;Stop! Try to read this interested book:, &lt;/p&gt;
</description></item><item><title>re: Sample code for parsing FtpwebRequest response for ListDirectoryDetails</title><link>http://blogs.msdn.com/adarshk/archive/2004/09/15/sample-code-for-parsing-ftpwebrequest-response-for-listdirectorydetails.aspx#8600878</link><pubDate>Sun, 15 Jun 2008 15:52:45 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8600878</guid><dc:creator>Sntzjyhf</dc:creator><description>&lt;p&gt;Try to look here and may be you find what do you want:, &lt;/p&gt;
</description></item><item><title>re: Sample code for parsing FtpwebRequest response for ListDirectoryDetails</title><link>http://blogs.msdn.com/adarshk/archive/2004/09/15/sample-code-for-parsing-ftpwebrequest-response-for-listdirectorydetails.aspx#8652328</link><pubDate>Wed, 25 Jun 2008 18:09:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8652328</guid><dc:creator>Kvovydtq</dc:creator><description>&lt;p&gt;Of course, but what do you think about that?, &lt;/p&gt;
</description></item><item><title>re: Sample code for parsing FtpwebRequest response for ListDirectoryDetails</title><link>http://blogs.msdn.com/adarshk/archive/2004/09/15/sample-code-for-parsing-ftpwebrequest-response-for-listdirectorydetails.aspx#8984854</link><pubDate>Tue, 07 Oct 2008 16:11:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8984854</guid><dc:creator>DM</dc:creator><description>&lt;p&gt;Do you know what is refactoring?&lt;/p&gt;
</description></item><item><title>re: Sample code for parsing FtpwebRequest response for ListDirectoryDetails</title><link>http://blogs.msdn.com/adarshk/archive/2004/09/15/sample-code-for-parsing-ftpwebrequest-response-for-listdirectorydetails.aspx#9014664</link><pubDate>Fri, 24 Oct 2008 16:10:38 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9014664</guid><dc:creator>Will</dc:creator><description>&lt;p&gt;Do you have this sample written in VB code?&lt;/p&gt;
</description></item><item><title>re: Sample code for parsing FtpwebRequest response for ListDirectoryDetails</title><link>http://blogs.msdn.com/adarshk/archive/2004/09/15/sample-code-for-parsing-ftpwebrequest-response-for-listdirectorydetails.aspx#9575476</link><pubDate>Wed, 29 Apr 2009 13:37:25 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9575476</guid><dc:creator>Stephen</dc:creator><description>&lt;p&gt;the date.pase() method which parses the concacated date and time was crapping out as my culture was &amp;quot;en-GB&amp;quot;, it's betst to add a private field like &lt;/p&gt;
&lt;p&gt;private CultureInfo _cultureInfo = CultureInfo.CreateSpecificCulture(&amp;quot;en-US&amp;quot;);&lt;/p&gt;
&lt;p&gt;And then in the line where the date is parsed, it is changed to &lt;/p&gt;
&lt;p&gt;f.CreateTime = DateTime.Parse(dateStr + &amp;quot; &amp;quot; + timeStr, _cultureInfo);&lt;/p&gt;
&lt;p&gt;that way, it will know that it is parsing a US style date.&lt;/p&gt;
&lt;p&gt;great work by the way, this has saved me at least two days of work!&lt;/p&gt;
</description></item><item><title>re: Sample code for parsing FtpwebRequest response for ListDirectoryDetails</title><link>http://blogs.msdn.com/adarshk/archive/2004/09/15/sample-code-for-parsing-ftpwebrequest-response-for-listdirectorydetails.aspx#9609019</link><pubDate>Wed, 13 May 2009 12:06:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9609019</guid><dc:creator>sunss</dc:creator><description>&lt;p&gt;DeMi's alternative code seems to work as well (and seems a little neater!). &amp;nbsp;The only bug I've found is changing the 2nd occurence of:&lt;/p&gt;
&lt;p&gt;return ParseMatch(match.Groups, ListStyle.Unix);&lt;/p&gt;
&lt;p&gt;to&lt;/p&gt;
&lt;p&gt;return ParseMatch(match.Groups, ListStyle.Windows);&lt;/p&gt;
</description></item><item><title>re: Sample code for parsing FtpwebRequest response for ListDirectoryDetails</title><link>http://blogs.msdn.com/adarshk/archive/2004/09/15/sample-code-for-parsing-ftpwebrequest-response-for-listdirectorydetails.aspx#9723923</link><pubDate>Wed, 10 Jun 2009 14:11:42 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9723923</guid><dc:creator>tynar</dc:creator><description>&lt;p&gt;Regex for FileZilla Server;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; private Regex fileZilla = new Regex(@&amp;quot;(?&amp;lt;dir&amp;gt;[-dl])(?&amp;lt;ownerSec&amp;gt;)[-r][-w][-x](?&amp;lt;groupSec&amp;gt;)[-r][-w][-x](?&amp;lt;everyoneSec&amp;gt;)[-r][-w][-x]\s+(?:\d)\s+(?&amp;lt;owner&amp;gt;\w+)\s+(?&amp;lt;group&amp;gt;\w+)\s+(?&amp;lt;size&amp;gt;\d+)\s+(?&amp;lt;month&amp;gt;\w+)\s+(?&amp;lt;day&amp;gt;\d{1,2})\s+(?&amp;lt;year&amp;gt;\w+)\s+(?&amp;lt;name&amp;gt;.*)$&amp;quot;);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;match = fileZilla.Match(line);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if (match.Success)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return ParseMatch(match.Groups, ListStyle.Unix);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
</description></item><item><title>re: Sample code for parsing FtpwebRequest response for ListDirectoryDetails</title><link>http://blogs.msdn.com/adarshk/archive/2004/09/15/sample-code-for-parsing-ftpwebrequest-response-for-listdirectorydetails.aspx#9817840</link><pubDate>Sun, 05 Jul 2009 06:29:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9817840</guid><dc:creator>家出</dc:creator><description>&lt;p&gt;これから家出したい少女や、現在家出中の娘とそんな娘を助けたい人を繋げるSOS掲示板です。10代、20代の女の子が家庭内の問題などでやむなく家出している子が多数書き込みしています。女の子リストを見て彼女たちにアプローチしてみませんか&lt;/p&gt;
</description></item><item><title>re: Sample code for parsing FtpwebRequest response for ListDirectoryDetails</title><link>http://blogs.msdn.com/adarshk/archive/2004/09/15/sample-code-for-parsing-ftpwebrequest-response-for-listdirectorydetails.aspx#9818663</link><pubDate>Mon, 06 Jul 2009 06:59:30 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9818663</guid><dc:creator>精神年齢</dc:creator><description>&lt;p&gt;みんなの精神年齢を測定できる、メンタル年齢チェッカーで秘められた年齢がズバリわかっちゃう！かわいいあの子も実は精神年齢オバサンということも…合コンや話のネタに一度チャレンジしてみよう&lt;/p&gt;
</description></item><item><title>re: Sample code for parsing FtpwebRequest response for ListDirectoryDetails</title><link>http://blogs.msdn.com/adarshk/archive/2004/09/15/sample-code-for-parsing-ftpwebrequest-response-for-listdirectorydetails.aspx#9821353</link><pubDate>Tue, 07 Jul 2009 06:34:46 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9821353</guid><dc:creator>童貞卒業</dc:creator><description>&lt;p&gt;童貞卒業を考えているなら、迷わずココ！今まで童貞とヤッた事がない女性というのは意外と多いものです。そんな彼女たちは一度童貞とやってみたいと考えるのは自然な事と言えるでしょう。当サイトにはそんな好奇心旺盛な女性たちが登録されています&lt;/p&gt;
</description></item><item><title>re: Sample code for parsing FtpwebRequest response for ListDirectoryDetails</title><link>http://blogs.msdn.com/adarshk/archive/2004/09/15/sample-code-for-parsing-ftpwebrequest-response-for-listdirectorydetails.aspx#9843822</link><pubDate>Tue, 21 Jul 2009 23:38:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9843822</guid><dc:creator>virt</dc:creator><description>&lt;p&gt;If your ftpsite requires authentication, use &lt;/p&gt;
&lt;p&gt;FtpWebRequest ftpclientRequest = WebRequest.Create(args[0]) as FtpWebRequest;&lt;/p&gt;
&lt;p&gt;ftpclientRequest.Credentials = new NetworkCredential(&amp;quot;username&amp;quot;, &amp;quot;password&amp;quot;);&lt;/p&gt;
</description></item><item><title>re: Sample code for parsing FtpwebRequest response for ListDirectoryDetails</title><link>http://blogs.msdn.com/adarshk/archive/2004/09/15/sample-code-for-parsing-ftpwebrequest-response-for-listdirectorydetails.aspx#9865376</link><pubDate>Wed, 12 Aug 2009 05:37:05 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9865376</guid><dc:creator>出会い</dc:creator><description>&lt;p&gt;即ハメセレブは完全無料でご利用できる出会いコミュニティです。今までにない実績で、あなたの希望に合った人をお探しします。毎月考えられない豪華なイベントを開催しているので出会いを保障します&lt;/p&gt;
</description></item></channel></rss>