Exemple #1
0
        private void PushDirectoryContents(LocalDirectory localDirectory, FtpPath ftpPath)
        {
            var pushTasks = new List <Task>();

            foreach (var local in localDirectory.EnumerateChildren())
            {
                var exclude = MatchExcludes(local.RelativePath);
                if (exclude != null)
                {
                    Log(local.Depth, ItemAction.Skip, local.Name, $"excluded ({exclude.Original})");
                    continue;
                }

                EnsureRemoteWorkingDirectory(ftpPath.Absolute);
                Log(local.Depth, ItemAction.Add, local.Name);
                pushTasks.Add(PushAnyAsync(local, ftpPath));
            }
            Task.WaitAll(pushTasks.ToArray());
        }
Exemple #2
0
        private void SynchronizeDirectory(LocalDirectory localDirectory, FtpPath ftpPath)
        {
            Log(localDirectory.Depth, ItemAction.Synchronize, localDirectory.Name);

            EnsureRemoteWorkingDirectory(ftpPath.Absolute);
            var allRemote = FtpRetry.ConnectedCall(_mainClient, ftpPath.Absolute, c => c.GetListing(".", FtpListOption.AllFiles))
                            .ToDictionary(l => l.Name, StringComparer.OrdinalIgnoreCase);
            var allRemoteFound = new HashSet <FtpListItem>();

            var pushTasks = new List <Task>();

            foreach (var local in localDirectory.EnumerateChildren())
            {
                var remote  = allRemote.GetValueOrDefault(local.Name);
                var exclude = MatchExcludes(local.RelativePath);
                if (exclude != null)
                {
                    Log(localDirectory.Depth + 1, ItemAction.Skip, local.Name, $"excluded ({exclude.Original})");
                    allRemoteFound.Add(remote);
                    continue;
                }

                EnsureRemoteWorkingDirectory(ftpPath.Absolute);

                if (remote != null)
                {
                    allRemoteFound.Add(remote);
                }

                var localAsDirectory = local as LocalDirectory;
                if (localAsDirectory != null)
                {
                    if (remote == null)
                    {
                        Log(localDirectory.Depth + 1, ItemAction.Add, localAsDirectory.Name);
                        PushDirectory(localAsDirectory, ftpPath);
                        continue;
                    }

                    if (remote.Type == FtpFileSystemObjectType.Directory)
                    {
                        SynchronizeDirectory(localAsDirectory, ftpPath.GetChildPath(remote.Name));
                        continue;
                    }

                    DeleteFtpFile(ftpPath.GetChildPath(remote.Name));
                    Log(localDirectory.Depth + 1, ItemAction.Add, localAsDirectory.Name);
                    PushDirectory(localAsDirectory, ftpPath);
                    continue;
                }

                var localAsFile = (LocalFile)local;
                var pushTask    = SynchronizeFileAsync(localAsFile, ftpPath, remote);
                if (pushTask != null)
                {
                    pushTasks.Add(pushTask);
                }
            }
            if (pushTasks.Count > 0)
            {
                Task.WaitAll(pushTasks.ToArray());
            }

            EnsureRemoteWorkingDirectory(ftpPath.Absolute);
            foreach (var missing in allRemote.Values.Except(allRemoteFound))
            {
                var missingPath = ftpPath.GetChildPath(missing.Name);
                var exclude     = MatchExcludes(missingPath.Relative);
                if (exclude != null)
                {
                    Log(localDirectory.Depth + 1, ItemAction.Skip, missing.Name, $"excluded ({exclude.Original})");
                    continue;
                }
                DeleteFtpAny(missingPath, missing.Type);
            }
        }