static void Download(WebDavConnection state, string args) { string[] v = Parse (args, 2); string s = v [0]; string d = v [1]; Stream dest = d != null ? File.OpenWrite (d) : Console.OpenStandardOutput (); try { using (var t = state.Builder.CreateDownloadMethodAsync (s, dest)) { try { t.Wait (); } catch (Exception e) { Console.Error.WriteLine ("webdav: {0}", e); return; } if (t.IsFaulted) { Console.Error.WriteLine ("webdav: {0}", t.Exception.Flatten ()); return; } Console.WriteLine ("StatusCode: {0}", t.Result.ResponseStatusCode); } } finally { if (d != null) dest.Close (); } }
static void ShowHelp(WebDavConnection state, string args) { Console.WriteLine("webdav commands--"); foreach (var name in Commands.Keys.OrderBy(k => k)) { var d = Commands [name]; var h = (HelpAttribute[])d.Method.GetCustomAttributes(typeof(HelpAttribute), false); var prefix = " " + name + ":"; if (h == null || h.Length == 0) { Console.WriteLine(prefix); continue; } if (prefix.Length > 10) { Console.WriteLine(prefix); prefix = new string (' ', 10); } else { prefix = prefix.PadRight(10); } foreach (var a in h) { foreach (var l in Mono.Options.StringCoda.WrappedLines(a.HelpText, 50, 48)) { Console.WriteLine("{0}{1}", prefix, l); prefix = new string (' ', 12); } } } }
static void Download(WebDavConnection state, string args) { string[] v = Parse(args, 2); string s = v [0]; string d = v [1]; Stream dest = d != null?File.OpenWrite(d) : Console.OpenStandardOutput(); try { using (var t = state.Builder.CreateDownloadMethodAsync(s, dest)) { try { t.Wait(); } catch (Exception e) { Console.Error.WriteLine("webdav: {0}", e); return; } if (t.IsFaulted) { Console.Error.WriteLine("webdav: {0}", t.Exception.Flatten()); return; } Console.WriteLine("StatusCode: {0}", t.Result.ResponseStatusCode); } } finally { if (d != null) { dest.Close(); } } }
static void Server(WebDavConnection state, string server) { if (!string.IsNullOrEmpty(server)) { state.Builder.Server = new Uri(server); } else { Console.WriteLine("Server: {0}", state.Builder.Server); } }
static void SetLogging(WebDavConnection state, string args) { if (string.IsNullOrEmpty(args)) { Console.WriteLine(state.Builder.Log != null); return; } if (args == "1" || args == "true") { state.Builder.Log = Console.Out; } else { state.Builder.Log = null; } }
static void ListPath(WebDavConnection state, string args) { string[] v = Parse(args, 3); string p = v [0]; int? d = v [1] == null ? null : (int?)int.Parse(v [1]); string x = v [2]; XElement r = null; if (x != null) { try { r = XElement.Parse(x); } catch (Exception e) { Console.Error.WriteLine("Invalid XML in '{0}': {1}", x, e.Message); return; } } using (var t = state.Builder.CreateFileStatusMethodAsync(p, d, r)) { try { t.Wait(); } catch (Exception e) { Console.Error.WriteLine("webdav: {0}", e); return; } if (t.IsFaulted) { Console.Error.WriteLine("webdav: {0}", t.Exception.Flatten()); return; } foreach (var e in t.Result.GetResponses()) { Console.WriteLine("{0} {1,10} {2,-12} {3}", e.ResourceType == null ? " " : e.ResourceType == WebDavResourceType.Collection ? "d" : "-", e.ContentLength, e.CreationDate == null ? "" : e.CreationDate.Value.ToString("MMM d HH:MM"), e.Href); } } }
static void Exit(WebDavConnection state, string ignored) { Environment.Exit(0); }
public static void Main(string[] args) { var c = new WebDavConnection(); bool show_help = false; bool show_version = false; var o = new OptionSet { "Usage: webdav [OPTIONS]", "", "Simple WebDav command-line client to excercise WebDavClient.", "", "Options:", { "server=", "Set name of WebDAV {SERVER} to connect to.", v => c.Builder.Server = new Uri(v) }, { "user="******"Set {USERNAME} on WebDAV server to connect to.", v => (c.Builder.NetworkCredential ?? (c.Builder.NetworkCredential = new NetworkCredential())).UserName = v }, { "pass="******"Set {PASSWORD} on WebDAV server to connect to.", v => (c.Builder.NetworkCredential ?? (c.Builder.NetworkCredential = new NetworkCredential())).Password = v }, { "v", "Show verbose communication information.", v => c.Builder.Log = Console.Out }, { "version", "Show version information and exit.", v => show_version = v != null }, { "help|h|?", "Show this message and exit.", v => show_help = v != null }, }; try { o.Parse(args); } catch (Exception ex) { Console.Error.WriteLine("webdav: {0}", ex.Message); } if (show_version) { Console.WriteLine("webdav 0.1"); return; } if (show_help) { o.WriteOptionDescriptions(Console.Out); return; } LineEditor e = new LineEditor("webdav"); string s; while ((s = e.Edit("webdav> ", "")) != null) { if ((s = s.Trim()).Length == 0) { continue; } var p = s.IndexOf(' '); var m = p < 0 ? s : s.Substring(0, p); var a = WebDavConnection.GetCommand(m); if (a == null) { Console.Error.WriteLine("webdav: Invalid command: {0}", s); continue; } while (p > 0 && p < s.Length && char.IsWhiteSpace(s, p)) { ++p; } s = p >= 0 && p < s.Length ? s.Substring(p) : ""; a(c, s); } }
public static void Main(string[] args) { var c = new WebDavConnection (); bool show_help = false; bool show_version = false; var o = new OptionSet { "Usage: webdav [OPTIONS]", "", "Simple WebDav command-line client to excercise WebDavClient.", "", "Options:", { "server=", "Set name of WebDAV {SERVER} to connect to.", v => c.Builder.Server = new Uri (v) }, { "user="******"Set {USERNAME} on WebDAV server to connect to.", v => (c.Builder.NetworkCredential ?? (c.Builder.NetworkCredential = new NetworkCredential ())).UserName = v }, { "pass="******"Set {PASSWORD} on WebDAV server to connect to.", v => (c.Builder.NetworkCredential ?? (c.Builder.NetworkCredential = new NetworkCredential ())).Password = v }, { "v", "Show verbose communication information.", v => c.Builder.Log = Console.Out }, { "version", "Show version information and exit.", v => show_version = v != null }, { "help|h|?", "Show this message and exit.", v => show_help = v != null }, }; try { o.Parse (args); } catch (Exception ex) { Console.Error.WriteLine ("webdav: {0}", ex.Message); } if (show_version) { Console.WriteLine ("webdav 0.1"); return; } if (show_help) { o.WriteOptionDescriptions (Console.Out); return; } LineEditor e = new LineEditor ("webdav"); string s; while ((s = e.Edit ("webdav> ", "")) != null) { if ((s = s.Trim ()).Length == 0) continue; var p = s.IndexOf (' '); var m = p < 0 ? s : s.Substring (0, p); var a = WebDavConnection.GetCommand (m); if (a == null) { Console.Error.WriteLine ("webdav: Invalid command: {0}", s); continue; } while (p > 0 && p < s.Length && char.IsWhiteSpace (s, p)) ++p; s = p >= 0 && p < s.Length ? s.Substring (p) : ""; a (c, s); } }
static void ShowHelp(WebDavConnection state, string args) { Console.WriteLine ("webdav commands--"); foreach (var name in Commands.Keys.OrderBy (k => k)) { var d = Commands [name]; var h = (HelpAttribute[]) d.Method.GetCustomAttributes (typeof (HelpAttribute), false); var prefix = " " + name + ":"; if (h == null || h.Length == 0) { Console.WriteLine (prefix); continue; } if (prefix.Length > 10) { Console.WriteLine (prefix); prefix = new string (' ', 10); } else { prefix = prefix.PadRight (10); } foreach (var a in h) foreach (var l in Mono.Options.StringCoda.WrappedLines (a.HelpText, 50, 48)) { Console.WriteLine ("{0}{1}", prefix, l); prefix = new string (' ', 12); } } }
static void SetLogging(WebDavConnection state, string args) { if (string.IsNullOrEmpty (args)) { Console.WriteLine (state.Builder.Log != null); return; } if (args == "1" || args == "true") state.Builder.Log = Console.Out; else state.Builder.Log = null; }
static void Server(WebDavConnection state, string server) { if (!string.IsNullOrEmpty (server)) state.Builder.Server = new Uri (server); else Console.WriteLine ("Server: {0}", state.Builder.Server); }
static void ListPath(WebDavConnection state, string args) { string[] v = Parse (args, 3); string p = v [0]; int? d = v [1] == null ? null : (int?) int.Parse (v [1]); string x = v [2]; XElement r = null; if (x != null) { try { r = XElement.Parse (x); } catch (Exception e) { Console.Error.WriteLine ("Invalid XML in '{0}': {1}", x, e.Message); return; } } using (var t = state.Builder.CreateFileStatusMethodAsync (p, d, r)) { try { t.Wait (); } catch (Exception e) { Console.Error.WriteLine ("webdav: {0}", e); return; } if (t.IsFaulted) { Console.Error.WriteLine ("webdav: {0}", t.Exception.Flatten ()); return; } foreach (var e in t.Result.GetResponses ()) { Console.WriteLine ("{0} {1,10} {2,-12} {3}", e.ResourceType == null ? " " : e.ResourceType == WebDavResourceType.Collection ? "d" : "-", e.ContentLength, e.CreationDate == null ? "" : e.CreationDate.Value.ToString ("MMM d HH:MM"), e.Href); } } }
static void Exit(WebDavConnection state, string ignored) { Environment.Exit (0); }