From: Gonzalo Paniagua Javier Date: Fri, 16 Jan 2009 15:40:23 +0000 (-0000) Subject: 2009-01-16 Gonzalo Paniagua Javier X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=4181e287351396429e922779103930bc640058de;p=mono.git 2009-01-16 Gonzalo Paniagua Javier * FtpWebRequestTest.cs: add directory listing test when the $HOME is not /. svn path=/trunk/mcs/; revision=123616 --- diff --git a/mcs/class/System/Test/System.Net/ChangeLog b/mcs/class/System/Test/System.Net/ChangeLog index c73f01167c5..1405437c55d 100644 --- a/mcs/class/System/Test/System.Net/ChangeLog +++ b/mcs/class/System/Test/System.Net/ChangeLog @@ -1,4 +1,9 @@ +2009-01-16 Gonzalo Paniagua Javier + + * FtpWebRequestTest.cs: add directory listing test when the $HOME is + not /. + 2009-01-12 Gonzalo Paniagua Javier * FtpWebRequestTest.cs: test deleting a file. diff --git a/mcs/class/System/Test/System.Net/FtpWebRequestTest.cs b/mcs/class/System/Test/System.Net/FtpWebRequestTest.cs index af21ebd0ab1..7c05b4224d0 100644 --- a/mcs/class/System/Test/System.Net/FtpWebRequestTest.cs +++ b/mcs/class/System/Test/System.Net/FtpWebRequestTest.cs @@ -254,6 +254,95 @@ namespace MonoTests.System.Net } } + [Test] + public void ListDirectory1 () + { + ServerListDirectory sp = new ServerListDirectory (); + sp.Start (); + string uri = String.Format ("ftp://{0}:{1}/somedir/", sp.IPAddress, sp.Port); + try { + FtpWebRequest ftp = (FtpWebRequest) WebRequest.Create (uri); + Console.WriteLine (ftp.RequestUri); + ftp.KeepAlive = false; + ftp.Timeout = 5000; + ftp.Method = WebRequestMethods.Ftp.ListDirectoryDetails; + ftp.UseBinary = true; + using (FtpWebResponse response = (FtpWebResponse) ftp.GetResponse ()) { + StreamReader reader = new StreamReader (response.GetResponseStream ()); + string result = reader.ReadToEnd (); + Assert.IsTrue ((int) response.StatusCode >= 200 && (int) response.StatusCode < 300, "DF#01"); + } + } catch (Exception e) { + Console.WriteLine (e); + if (!String.IsNullOrEmpty (sp.Where)) + throw new Exception (sp.Where); + throw; + } finally { + sp.Stop (); + } + } + + class ServerListDirectory : FtpServer { + protected override void Run () + { + Socket client = control.Accept (); + NetworkStream ns = new NetworkStream (client, false); + StreamWriter writer = new StreamWriter (ns, Encoding.ASCII); + StreamReader reader = new StreamReader (ns, Encoding.UTF8); + if (!DoAnonymousLogin (writer, reader)) { + client.Close (); + return; + } + + if (!DoInitialDialog (writer, reader, "/home/someuser", "/home/someuser/somedir/")) { + client.Close (); + return; + } + + string str = reader.ReadLine (); + if (str != "PASV") { + Where = "PASV"; + client.Close (); + return; + } + + IPEndPoint end_data = (IPEndPoint) data.LocalEndPoint; + byte [] addr_bytes = end_data.Address.GetAddressBytes (); + byte [] port = new byte [2]; + port[0] = (byte) ((end_data.Port >> 8) & 255); + port[1] = (byte) (end_data.Port & 255); + StringBuilder sb = new StringBuilder ("227 Passive ("); + foreach (byte b in addr_bytes) { + sb.AppendFormat ("{0},", b); + } + sb.AppendFormat ("{0},", port [0]); + sb.AppendFormat ("{0})", port [1]); + writer.WriteLine (sb.ToString ()); + writer.Flush (); + + str = reader.ReadLine (); + if (str != "LIST") { + Where = "LIST - '" + str + "'"; + client.Close (); + return; + } + writer.WriteLine ("150 Here comes the directory listing"); + writer.Flush (); + + Socket data_cnc = data.Accept (); + byte [] dontcare = Encoding.ASCII.GetBytes ("drwxr-xr-x 2 ftp ftp 4096 Oct 27 20:17 tests"); + data_cnc.Send (dontcare, 1, SocketFlags.None); + data_cnc.Close (); + writer.WriteLine ("226 Directory send Ok"); + writer.Flush (); + if (!EndConversation (writer, reader)) { + client.Close (); + return; + } + client.Close (); + } + } + class ServerDeleteFile : FtpServer { protected override void Run () {