public static bool UploadAllViaZip(string ftpserver, string user, string password, string zip, int index, int batch)
        {
            var        fileStream = File.OpenRead(zip);
            bool       isFinished = false;
            ZipArchive archive    = new ZipArchive(fileStream);

            if (archive.Entries.Count - index <= batch)
            {
                batch      = archive.Entries.Count;
                isFinished = true;
            }
            else
            {
                batch += index;
            }

            Dictionary <string, bool> directoryCreated = new Dictionary <string, bool>();

            for (int i = index; i < batch; i++)
            {
                Debug.WriteLine(i + " of " + archive.Entries.Count);
                var entry     = archive.Entries[i];
                var directory = entry.FullName.Remove(entry.FullName.LastIndexOf('/'));
                if (!directoryCreated.ContainsKey(directory))
                {
                    directoryCreated.Add(directory, true);
                    UploadFolder(ftpserver, user, password, directory);
                }

                byte[] data = new byte[entry.Length];
                using (var stream = entry.Open())
                {
                    stream.Read(data, 0, (int)entry.Length);
                }

                if (!(string.IsNullOrEmpty(entry.Name)))
                {
                    RetryUtility.Retry(() =>
                                       UploadFile(ftpserver, user, password, entry.FullName, data));
                }
            }

            return(isFinished);
        }
Beispiel #2
0
 public static void Retry(Action func)
 {
     RetryUtility.Retry(retries, func);
 }