+ [Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
+ public void DownloadFile2_v4 ()
+ {
+ // Some embedded FTP servers in Industrial Automation Hardware report
+ // the PWD using backslashes, but allow forward slashes for CWD.
+ DownloadFile (new ServerDownload (@"\Users\someuser", "/Users/someuser/", null, false));
+ }
+
+ [Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
+ public void DownloadFile2_v6 ()
+ {
+ if (!Socket.OSSupportsIPv6)
+ Assert.Ignore ("IPv6 not supported.");
+
+ // Some embedded FTP servers in Industrial Automation Hardware report
+ // the PWD using backslashes, but allow forward slashes for CWD.
+ DownloadFile (new ServerDownload (@"\Users\someuser", "/Users/someuser/", null, true));
+ }
+
+ [Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
+ public void DeleteFile1_v4 ()
+ {
+ DeleteFile1 (false);
+ }
+
+ [Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
+ public void DeleteFile1_v6 ()
+ {
+ if (!Socket.OSSupportsIPv6)
+ Assert.Ignore ("IPv6 not supported.");
+
+ DeleteFile1 (true);
+ }
+
+ void DeleteFile1 (bool ipv6)
+ {
+ ServerDeleteFile sp = new ServerDeleteFile (ipv6);
+ sp.Start ();
+ string uri = String.Format ("ftp://{0}:{1}/file.txt", EncloseIPv6 (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.DeleteFile;
+ ftp.UseBinary = true;
+ FtpWebResponse response = (FtpWebResponse) ftp.GetResponse ();
+ Assert.IsTrue ((int) response.StatusCode >= 200 && (int) response.StatusCode < 300, "DF#01");
+ response.Close ();
+ } catch (Exception e) {
+ Console.WriteLine (e);
+ if (!String.IsNullOrEmpty (sp.Where))
+ throw new Exception (sp.Where);
+ throw;
+ } finally {
+ sp.Stop ();
+ }
+ }
+
+ [Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
+ public void ListDirectory1_v4 ()
+ {
+ ListDirectory1 (false);
+ }
+
+ [Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
+ public void ListDirectory1_v6 ()
+ {
+ if (!Socket.OSSupportsIPv6)
+ Assert.Ignore ("IPv6 not supported.");
+
+ ListDirectory1 (true);
+ }
+
+ void ListDirectory1 (bool ipv6)
+ {
+ ServerListDirectory sp = new ServerListDirectory (ipv6);
+ sp.Start ();
+ string uri = String.Format ("ftp://{0}:{1}/somedir/", EncloseIPv6 (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 ();
+ }
+ }
+
+ string EncloseIPv6 (IPAddress address)
+ {
+ if (address.AddressFamily == AddressFamily.InterNetwork)
+ return address.ToString ();
+
+ return String.Format ("[{0}]", address.ToString ());
+ }
+
+ class ServerListDirectory : FtpServer {
+ public ServerListDirectory (bool ipv6)
+ : base (ipv6)
+ {
+ }
+
+ 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 ();
+ string resp = FormatPassiveResponse (str);
+ if (resp == null) {
+ client.Close ();
+ return;
+ }
+ writer.WriteLine (resp);
+ 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 {
+ public ServerDeleteFile (bool ipv6)
+ : base (ipv6)
+ {
+ }
+