public async Task <DateTime> LatestSync(FolderMapping mapping)
        {
            if (mapping == null || mapping.FriendlyName == null)
            {
                return(DateTime.MinValue);
            }

            string path = folderRoot + mapping.FriendlyName + "/";

            if (!await client.DirectoryExistsAsync(path))
            {
                return(DateTime.MinValue);
            }

            FtpListItem[] folders = await client.GetListingAsync(path);

            if (folders.Length == 0)
            {
                return(DateTime.MinValue);
            }

            List <DateTime> folderDateTimes = folders.Select(x => DateTimeDirUtils.GetDirDateTime(x.Name)).ToList();

            folderDateTimes.Sort();
            return(folderDateTimes.Last());
        }
        private async Task <int> GetRemoteFilesCount(FolderMapping mapping)
        {
            DateTime latestSync = await LatestSync(mapping);

            string remotePath = folderRoot + mapping.FriendlyName + "/" + DateTimeDirUtils.GetDirDateTimeString(latestSync) + "/";

            List <FtpListItem> files = await client.GetRecursiveListing(remotePath);

            return(files.Count);
        }
        private async Task <int> GetRemoteFilesCount(string[] friendlyNames)
        {
            for (int i = 0; i < friendlyNames.Length; i++)
            {
                DateTime latestSync = await LatestSync(friendlyNames[i]);

                friendlyNames[i] = folderRoot + friendlyNames[i] + "/" + DateTimeDirUtils.GetDirDateTimeString(latestSync) + "/";
            }

            List <FtpListItem> files = await client.GetRecursiveListing(friendlyNames);

            return(files.Count);
        }
        private async Task DownloadFolderImpl(FolderMapping mapping, ProgressBarStepper stepper)
        {
            DateTime latestSync = await LatestSync(mapping);

            string remotePath = folderRoot + mapping.FriendlyName + "/" + DateTimeDirUtils.GetDirDateTimeString(latestSync) + "/";

            List <FtpListItem> remoteFiles = await client.GetRecursiveListing(remotePath);

            foreach (FtpListItem file in remoteFiles)
            {
                string clientSidePath = mapping.ClientSidePath + @"\" + file.FullName.Substring(remotePath.Length).Replace("/", @"\");
                await client.DownloadFileAsync(clientSidePath, file.FullName, true, FtpVerify.Retry);

                File.SetLastWriteTime(clientSidePath, latestSync);
                progressUpdateAction.Invoke(stepper.Step());
            }
        }
        private async Task UploadFolderImpl(FolderMapping mapping, ProgressBarStepper stepper)
        {
            string[] files     = GetLocalFiles(mapping.ClientSidePath);
            var      filePaths = from f in files
                                 select f.Substring(mapping.ClientSidePath.Length);

            DateTime uploadDateTime       = DirUtils.GetLatestFileWriteTimeInDir(mapping.ClientSidePath);
            string   datetimeFolderString = DateTimeDirUtils.GetDirDateTimeString(uploadDateTime);
            string   serverSideFolderPath = folderRoot + mapping.FriendlyName + "/" + datetimeFolderString;

            client.CreateDirectory(serverSideFolderPath);

            foreach (string file in filePaths)
            {
                string uploadPath = serverSideFolderPath + file.Replace(@"\", "/");
                await client.UploadFileAsync(mapping.ClientSidePath + file, uploadPath, FtpExists.Overwrite, true, FtpVerify.Retry);

                progressUpdateAction.Invoke(stepper.Step());
            }
        }
        private async Task <DateTime> LatestSync(string friendlyName)
        {
            string path = folderRoot + friendlyName + "/";

            if (!await client.DirectoryExistsAsync(path))
            {
                return(DateTime.MinValue);
            }

            FtpListItem[] folders = await client.GetListingAsync(path);

            if (folders.Length == 0)
            {
                return(DateTime.MinValue);
            }

            List <DateTime> folderDateTimes = folders.Select(x => DateTimeDirUtils.GetDirDateTime(x.Name)).ToList();

            folderDateTimes.Sort();
            return(folderDateTimes.Last());
        }