private static int Main(string[] args) { Arguments arguments; try { arguments = new Arguments(args); } catch (ArgumentException e) { Console.Error.WriteLine(e.Message); return(1); } catch (Exception e) { Console.Error.WriteLine($"Unknown error while parsing arguments: {e.Message}"); return(0); } if (arguments.HelpRequested) { Console.WriteLine(arguments.GetHelp(arguments.HelpTopic)); return(0); } var additionalPaths = new List <string>(); if (Platform.IsInputRedirected) { string input = null; while ((input = Console.In.ReadLine()) != null) { input = Environment.ExpandEnvironmentVariables(input); additionalPaths.Add(input); } } List <string> paths; try { paths = CollectionPaths.GetPaths(arguments, additionalPaths, arguments.Usnjrnl, arguments.AntiV); } catch (Exception e) { Console.Error.WriteLine($"Error occured while collecting files:\n{e}"); return(1); } var stopwatch = new Stopwatch(); stopwatch.Start(); //try //{ // var archiveStream = Stream.Null; // if (!arguments.DryRun) // { // var outputPath = $@"{arguments.OutputPath}/{arguments.OutputFileName}"; // if (arguments.UseSftp) // { // var client = CreateSftpClient(arguments); // archiveStream = client.Create(outputPath); // } // else // { // archiveStream = OpenFileStream(outputPath); // } // } // using (archiveStream) // { // CreateArchive(arguments, archiveStream, paths); // } // stopwatch.Stop(); // Console.WriteLine("Extraction complete. {0} elapsed", new TimeSpan(stopwatch.ElapsedTicks).ToString("g")); //} //catch (Exception e) //{ // Console.Error.WriteLine($"Error occured while collecting files:\n{e}"); // return 1; //} //return 0; try { var archiveStream = Stream.Null; var outputPath = $@"{arguments.OutputPath}/{arguments.OutputFileName}"; if (!arguments.DryRun) { archiveStream = OpenFileStream(outputPath); } using (archiveStream) { CreateArchive(arguments, archiveStream, paths); } stopwatch.Stop(); if (arguments.UseSftp) { // Attempt upload of SFTP. Console.WriteLine($"Attempting to upload to SFTP."); SFTPUpload(arguments, outputPath); } } catch (Exception e) { Console.WriteLine($"Upload failed. Please upload the local zip collection manually."); return(1); } return(0); }
private static void Main(string[] args) { Arguments arguments; try { arguments = new Arguments(args); } catch (ArgumentException e) { Console.WriteLine(e.Message); return; } catch (Exception e) { Console.WriteLine($"Unknown error while parsing arguments: {e.Message}"); return; } if (arguments.HelpRequested) { Console.WriteLine(arguments.GetHelp(arguments.HelpTopic)); return; } List <string> paths; try { paths = CollectionPaths.GetPaths(arguments); } catch (Exception e) { Console.WriteLine($"Error occured while collecting files:\n{e}"); return; } var stopwatch = new Stopwatch(); stopwatch.Start(); try { var archiveStream = Stream.Null; if (!arguments.DryRun) { if (arguments.UseSftp) { var client = CreateSftpClient(arguments); archiveStream = client.Create($@"{arguments.OutputPath}/{Environment.MachineName}.zip"); } else { archiveStream = OpenFileStream($@"{arguments.OutputPath}/{Environment.MachineName}.zip"); } } using (archiveStream) { CreateArchive(arguments, archiveStream, paths); } stopwatch.Stop(); Console.WriteLine("Extraction complete. {0} elapsed", new TimeSpan(stopwatch.ElapsedTicks).ToString("g")); } catch (Exception e) { Console.WriteLine($"Error occured while collecting files:\n{e}"); } }
private static int Main(string[] args) { Arguments arguments; try { arguments = new Arguments(args); } catch (ArgumentException e) { Console.Error.WriteLine(e.Message); return(1); } catch (Exception e) { Console.Error.WriteLine($"Unknown error while parsing arguments: {e.Message}"); return(0); } if (arguments.HelpRequested) { Console.WriteLine(arguments.GetHelp(arguments.HelpTopic)); return(0); } var additionalPaths = new List <string>(); if (Platform.IsInputRedirected) { string input = null; while ((input = Console.In.ReadLine()) != null) { input = Environment.ExpandEnvironmentVariables(input); additionalPaths.Add(input); } } List <string> paths; try { paths = CollectionPaths.GetPaths(arguments, additionalPaths, arguments.Usnjrnl); } catch (Exception e) { Console.Error.WriteLine($"Error occured while collecting files:\n{e}"); return(1); } var stopwatch = new Stopwatch(); stopwatch.Start(); try { var archiveStream = Stream.Null; if (!arguments.DryRun) { var outputPath = $@"{arguments.OutputPath}/{arguments.OutputFileName}"; if (arguments.UseSftp) { //var client = CreateSftpClient(arguments); //archiveStream = client.Create(outputPath); archiveStream = OpenFileStream(outputPath); } else { archiveStream = OpenFileStream(outputPath); } } using (archiveStream) { CreateArchive(arguments, archiveStream, paths); } var outputPath1 = $@"{arguments.OutputPath}/{arguments.OutputFileName}"; var client = CreateSftpClient(arguments); stopwatch.Stop(); Console.WriteLine("Extraction complete. {0} elapsed", new TimeSpan(stopwatch.ElapsedTicks).ToString("g")); Console.WriteLine("Uploading..."); using (var zipfile = File.OpenRead(outputPath1)) { client.UploadFile(zipfile, arguments.OutputFileName); } Console.WriteLine("Upload finished."); } catch (Exception e) { Console.Error.WriteLine($"Error occured while collecting files:\n{e}"); return(1); } return(0); }
private static int Main(string[] args) { Arguments arguments; try { arguments = new Arguments(args); } catch (ArgumentException e) { Console.WriteLine(e.Message); return(1); } catch (Exception e) { Console.WriteLine($"Unknown error while parsing arguments: {e.Message}"); return(0); } if (arguments.HelpRequested) { Console.WriteLine(arguments.GetHelp(arguments.HelpTopic)); return(0); } if (!arguments.ForceNative) { var identity = WindowsIdentity.GetCurrent(); var principal = new WindowsPrincipal(identity); if (!principal.IsInRole(WindowsBuiltInRole.Administrator)) { Console.WriteLine( "Error, this program requires admin privliages to run unless --force-native is specified."); return(1); } } var additionalPaths = new List <string>(); if (Platform.IsInputRedirected) { string input = null; while ((input = Console.ReadLine()) != null) { input = Environment.ExpandEnvironmentVariables(input); additionalPaths.Add(input); } } List <string> paths; try { paths = CollectionPaths.GetPaths(arguments, additionalPaths); } catch (Exception e) { Console.WriteLine($"Error occured while collecting files:\n{e}"); return(1); } var stopwatch = new Stopwatch(); stopwatch.Start(); try { var archiveStream = Stream.Null; if (!arguments.DryRun) { var outputPath = $@"{arguments.OutputPath}/{arguments.OutputFileName}"; if (arguments.UseSftp) { var client = CreateSftpClient(arguments); archiveStream = client.Create(outputPath); } else { archiveStream = OpenFileStream(outputPath); } } using (archiveStream) { CreateArchive(arguments, archiveStream, paths); } stopwatch.Stop(); Console.WriteLine("Extraction complete. {0} elapsed", new TimeSpan(stopwatch.ElapsedTicks).ToString("g")); } catch (Exception e) { Console.WriteLine($"Error occured while collecting files:\n{e}"); return(1); } return(0); }
private static void Main(string[] args) { Arguments arguments; try { arguments = new Arguments(args); } catch (ArgumentException e) { Console.WriteLine(e.Message); return; } catch (Exception e) { Console.WriteLine($"Unknown error while parsing arguments: {e.Message}"); return; } if (arguments.HelpRequested) { Console.WriteLine(arguments.GetHelp(arguments.HelpTopic)); return; } Dictionary <char, List <string> > paths; try { paths = CollectionPaths.GetPaths(arguments); } catch (Exception e) { Console.WriteLine($"Error occured while collecting files:\n{e}"); return; } var stopwatch = new Stopwatch(); stopwatch.Start(); try { using (var archiveStream = arguments.SFTPInMemory ? new MemoryStream() : OpenFileStream($@"{arguments.OutputPath}\{Environment.MachineName}.zip")) { #if DOT_NET_4_0 using (var archive = new SharpZipArchive(archiveStream)) #else using (var archive = new NativeArchive(archiveStream)) #endif { foreach (var drive in paths) { var driveName = drive.Key; var system = FileSystem.GetFileSystem(drive.Key, FileAccess.Read); var files = drive.Value .SelectMany(path => system.GetFilesFromPath(path)) .Select(file => new Tuple <string, DiscFileInfo>($"{driveName}\\{file.FullName}", file)); archive.CollectFilesToArchive(files); } } if (arguments.SFTPCheck) { int port; var server = arguments.SFTPServer.Split(':'); try { port = int.Parse(server[1]); } catch (Exception) { port = 22; } Sftp.Sftp.SendUsingSftp(archiveStream, server[0], port, arguments.UserName, arguments.UserPassword, $@"{arguments.OutputPath}/{Environment.MachineName}.zip"); } } if (arguments.SFTPCheck) { if (File.Exists($@"{arguments.OutputPath}\{Environment.MachineName}.zip")) { File.Delete($@"{arguments.OutputPath}\{Environment.MachineName}.zip"); } } } catch (Exception e) { Console.WriteLine($"Error occured while collecting files:\n{e}"); } stopwatch.Stop(); Console.WriteLine("Extraction complete. {0} elapsed", new TimeSpan(stopwatch.ElapsedTicks).ToString("g")); }
private static int Main(string[] args) { Arguments arguments; try { arguments = new Arguments(args); } catch (ArgumentException e) { Console.Error.WriteLine(e.Message); return(1); } catch (Exception e) { Console.Error.WriteLine($"Unknown error while parsing arguments: {e.Message}"); return(0); } if (arguments.HelpRequested) { Console.WriteLine(arguments.GetHelp(arguments.HelpTopic)); return(0); } // Configure logging var logger = new CyLR.Logger(); if (arguments.LogFilePath.Length > 0) { logger.LoggingOptions["output_file_path"] = arguments.LogFilePath; } if (arguments.EnableVerboseConsole) { logger.LoggingOptions["output_console_min_level"] = "debug"; } if (arguments.DisableLogging) { logger.LoggingOptions["output_file_enabled"] = "false"; logger.LoggingOptions["output_console_enabled"] = "false"; logger.LoggingOptions["output_buffer_enabled"] = "false"; } logger.Setup(); // Enumerate arguments logger.debug(String.Format("Argument {0} is set to {1}", "OutputPath", arguments.OutputPath)); logger.debug(String.Format("Argument {0} is set to {1}", "OutputFileName", arguments.OutputFileName)); logger.debug(String.Format("Argument {0} is set to {1}", "UserName", arguments.UserName)); logger.debug(String.Format("Argument {0} is set to {1}", "UserPassword", "[omitted in log file]")); logger.debug(String.Format("Argument {0} is set to {1}", "SFTPServer", arguments.SFTPServer)); logger.debug(String.Format("Argument {0} is set to {1}", "SFTPOutputPath", arguments.SFTPOutputPath)); logger.debug(String.Format("Argument {0} is set to {1}", "SFTPCleanUp", arguments.SFTPCleanUp)); logger.debug(String.Format("Argument {0} is set to {1}", "CollectionFilePath", arguments.CollectionFilePath)); logger.debug(String.Format("Argument {0} is set to {1}", "CollectDefaults", arguments.CollectDefaults)); logger.debug(String.Format("Argument {0} is set to {1}", "ZipPassword", "[omitted in log file]")); logger.debug(String.Format("Argument {0} is set to {1}", "ZipLevel", arguments.ZipLevel)); logger.debug(String.Format("Argument {0} is set to {1}", "LogFilePath", arguments.LogFilePath)); logger.debug(String.Format("Argument {0} is set to {1}", "DisableLogging", arguments.DisableLogging)); logger.debug(String.Format("Argument {0} is set to {1}", "EnableVerboseConsole", arguments.EnableVerboseConsole)); logger.debug(String.Format("Argument {0} is set to {1}", "Usnjrnl", arguments.Usnjrnl)); logger.debug(String.Format("Argument {0} is set to {1}", "ForceNative", arguments.ForceNative)); logger.debug(String.Format("Argument {0} is set to {1}", "DryRun", arguments.DryRun)); logger.debug(String.Format("Argument {0} is set to {1}", "CollectionFiles", arguments.CollectionFiles)); var additionalPaths = new List <string>(); if (Platform.IsInputRedirected) { string input = null; while ((input = Console.In.ReadLine()) != null) { input = Environment.ExpandEnvironmentVariables(input); additionalPaths.Add(input); } logger.debug("Identified additional collection paths from STDIN"); } List <string> paths; try { logger.info("Gathering paths to collect"); paths = CollectionPaths.GetPaths(arguments, additionalPaths, arguments.Usnjrnl, logger); logger.info(String.Format("{0} paths identified for collection", paths.Count)); } catch (Exception e) { logger.error($"Error occurred while collecting files:\n{e}"); logger.TearDown(); return(1); } var stopwatch = new Stopwatch(); stopwatch.Start(); try { var archiveStream = Stream.Null; var outputPath = $@"{arguments.OutputPath}/{arguments.OutputFileName}"; logger.debug(String.Format("Set outputPath to {0}", outputPath)); if (!arguments.DryRun) { logger.debug("Initializing archive file"); archiveStream = OpenFileStream(outputPath); } using (archiveStream) { logger.info("Adding files to archive"); CreateArchive(arguments, archiveStream, paths, logger); } stopwatch.Stop(); logger.info(String.Format("Collection complete. {0} elapsed", new TimeSpan(stopwatch.ElapsedTicks).ToString("g"))); if (arguments.UseSftp) { // Attempt upload of SFTP. logger.debug("Start SFTP Upload"); SFTPUpload(arguments, outputPath, logger); } } catch (Exception e) { logger.error($"Error occurred while collecting files:\n{e}"); logger.TearDown(); return(1); } return(0); }