Пример #1
0
        public LocalDirectory(FileOrDirectory parent, Uri url, SyncJob job)
        {
            Job    = job;
            Parent = parent;
            if (!url.ToString().Contains(':'))
            {
                if (url.ToString() == ".")
                {
                    url = new Uri(Environment.CurrentDirectory);
                }
                else
                {
                    url = new Uri(System.IO.Path.Combine(Environment.CurrentDirectory, url.ToString()));
                }
            }
            if (!url.IsFile)
            {
                throw new NotSupportedException("url is no local file.");
            }
            Url = url;
            var info = new DirectoryInfo(Path);

            Name       = info.Name;
            Class      = ObjectClass.Directory;
            ChangedUtc = info.LastWriteTimeUtc;
        }
Пример #2
0
 public static IDirectory Parse(Uri url, SyncJob job)
 {
     if (url.IsFile || !url.ToString().Contains(':'))
     {
         return(new LocalDirectory(null, url, job));
     }
     else
     {
         return(new FtpDirectory(null, url, job));
     }
 }
Пример #3
0
 public FtpDirectory(FileOrDirectory parent, Uri url, SyncJob job)
 {
     Job    = job;
     Parent = parent;
     if (url.Scheme != "ftp" && url.Scheme != "ftps")
     {
         throw new NotSupportedException();
     }
     Url     = url;
     Name    = url.File();
     Class   = ObjectClass.Directory;
     Changed = DateTime.Now.AddDays(2);
     if (parent is FtpDirectory)
     {
         TransferProgress = ((FtpDirectory)parent).TransferProgress;
     }
 }
Пример #4
0
 public FtpStream(SyncJob job) : base()
 {
     start = DateTime.Now; Job = job;
 }
Пример #5
0
        static void Main(string[] argsarr)
        {
            var args = new Arguments(argsarr);

            bool wait = false;

            var job = new SyncJob();

            try {
                if (args.Count < 2 || 7 < args.Count)
                {
                    Console.Write(WelcomeMsg);
                    Console.WriteLine("");
                    Console.WriteLine("Usage: sync sourceurl desturl [/update | /clone | /add] [/x excludepatterns] [logfilename] [/v] [/q]");
                    Console.WriteLine();
                    Console.WriteLine("- Urls can be either ftp urls or local paths");
                    Console.WriteLine("- Ftp urls are of the form protocol://username:password@server:port/path?ftp-options");
                    Console.WriteLine("  Ftp urls must be url encoded. For example a space must be written as %20.");
                    Console.WriteLine("- Protocol can be either ftp or ftps");
                    Console.WriteLine("- Ftp-options are delimited by a & and are of the form parameter or parameter=value");
                    Console.WriteLine("- Available ftp-options are:");
                    Console.WriteLine("  - \"passive\" for passive ftp mode");
                    Console.WriteLine("  - \"active\" for active ftp mode");
                    Console.WriteLine("  - \"connections\" for the number of concurrent connections");
                    Console.WriteLine("  - \"zip\" for compression if the server supports it");
                    Console.WriteLine("  - \"raw\" for no compression");
                    Console.WriteLine("  - \"old\" to use the most compatible ftp command set for old ftp servers");
                    Console.WriteLine("  - \"time\" for the server's time offset to utc time. If you omit time, sync");
                    Console.WriteLine("    will autodetect the time offset (The MDTM command must be supported by the server for this).");
                    Console.WriteLine("  - \"crc\" for auto CRC32 data transfer checksum check.");
                    Console.WriteLine("  - \"md5\" for auto MD5 data transfer checksum check.");
                    Console.WriteLine("  - \"sha\" for auto SHA1 data transfer checksum check.");
                    Console.WriteLine("- The connections option reqires an int value that limits the maximum concurent connections.");
                    Console.WriteLine("- The default options are passive&connections=10");
                    Console.WriteLine("- The /update option tells sync to keep newer files in the destination.");
                    Console.WriteLine("- The /clone option tells sync to clone the source and discard all changes in the destination. This is the default.");
                    Console.WriteLine("- The /add option tells sync to add all files that are not present or outdated in the destination, but not");
                    Console.WriteLine("  to delete any files or overwrite newer files.");
                    Console.WriteLine("- With the /x you can specify a comma or semicolon separated list of exclude file patterns.");
                    Console.WriteLine("  Use / instead of \\ in patterns. Only one asterisk (*) is allowed per pattern, so instead of ");
                    Console.WriteLine("  myfolder/*.* you would write myfolder/* .");
                    Console.WriteLine("- You can redirect output to a logfile by specifying a logfile name.");
                    Console.WriteLine("- You can set the output to verbose mode with the /v switch or to quiet mode with the /q switch.");
                    return;
                }

                Uri src, dest;
                var srcarg  = args.Pop();
                var destarg = args.Pop();
                if (srcarg.Contains(':'))
                {
                    src = new Uri(srcarg);
                }
                else
                {
                    src = new Uri(System.IO.Path.Combine(Environment.CurrentDirectory, srcarg));
                }
                if (destarg.Contains(':'))
                {
                    dest = new Uri(destarg);
                }
                else
                {
                    dest = new Uri(System.IO.Path.Combine(Environment.CurrentDirectory, destarg));
                }
                job.LogFile = null;
                job.Verbose = false;

                job.Mode = CopyMode.Clone;
                if (args.Has("/update"))
                {
                    job.Mode = CopyMode.Update;
                }
                if (args.Has("/add"))
                {
                    job.Mode = CopyMode.Add;
                }
                if (args.Has("/clone"))
                {
                    job.Mode = CopyMode.Clone;
                }
                string ExcludePatterns = null;
                args.Has("/x", out ExcludePatterns);
                job.ExcludePatterns = ExcludePatterns ?? "";
                job.Verbose         = args.Has("/v");
                job.Quiet           = args.Has("/q");
                wait = args.Has("/w");
                //if (args.Has("/t")) SpeedTest.Test();
                job.LogFile = args.Pop();

                var now = DateTime.Now;
                job.Log.Text("######  " + now.ToShortDateString() + " " + now.ToShortTimeString() + "   " + WelcomeMsg);
                job.Log.Text("########################   Run sync without parameters for help.");
                job.Log.Text("");

                job.Directory(src, dest);
            } catch (Exception ex) {
                job.Log.Exception(ex);
            }

            if (wait)
            {
                Console.WriteLine("Press any key..."); Console.ReadKey();
            }
        }