Exemplo n.º 1
0
        public static bool RunBatchLines(IEnumerable <string> batchLines, params char[] splitChars)
        {
            splitChars = splitChars.Length > 0 ? splitChars : new char[] { ';' };

            var batchRuns = batchLines
                            .Select(x => x.Split(splitChars))
                            .Where(args => args.Length > Options.DESTINATION_DIRECTORY_INDEX)
                            .Select(args => Options.CreateFromArgs(args))
                            .GroupBy(x => x.ConnectionGroupKey)
                            .ToList();

            foreach (var batchGroup in batchRuns)
            {
                try
                {
                    var groupConnectionOptions = batchGroup.First();
                    using (var sshDeltaCopy = new SshDeltaCopy(groupConnectionOptions))
                    {
                        foreach (var batchElement in batchGroup)
                        {
                            sshDeltaCopy.DeployDirectory(batchElement.SourceDirectory, batchElement.DestinationDirectory);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Exception: {ex.Message}\n{ex.StackTrace}");
                }
            }

            return(true);
        }
Exemplo n.º 2
0
        public static int Main(string[] args)
        {
            try
            {
                if (args.Length > SshDeltaCopy.Options.DESTINATION_DIRECTORY_INDEX)
                {
                    var options = SshDeltaCopy.Options.CreateFromArgs(args);
                    using (var sshDeltaCopy = new SshDeltaCopy(options))
                    {
                        //sshDeltaCopy.RunSSHCommand("ls -al");
                        sshDeltaCopy.DeployDirectory(options.SourceDirectory, options.DestinationDirectory);
                        //var cmd = sshDeltaCopy.CreateSSHCommand("ls -al");
                        //var result = cmd.Execute();
                        //sshDeltaCopy.PrintTime(result);
                        //sshDeltaCopy.RunSSHCommand("df -h");
                    }
                }
                else if (args.Length > 0 && File.Exists(args[0]))
                {
                    SshDeltaCopy.RunBatchfile(args[0]);
                }
                else if (File.Exists(SshDeltaCopy.DefaultBatchFilename))
                {
                    SshDeltaCopy.RunBatchfile(SshDeltaCopy.DefaultBatchFilename);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Exception: {ex.Message}\n{ex.StackTrace}");
                return(-2);
            }

#if DEBUG
            System.Threading.Thread.Sleep(5000);
#endif

            return(0);
        }