private static void backup(FTPClient ftp, DirectoryInfo dir, Regex regex, RegistryKey key) { string[] files = ftp.Dir(null, true); string[] names = new string[files.Length]; int i = 0; foreach (string file in files) { names[i] = file.Substring(56); if (file.Substring(0,1) == "d") { // A directory! if (dir.GetDirectories(names[i]).Length != 1 && !names[i].Substring(0,1).Equals(".")) RecRm(ftp, names[i]); } else // A file! if (regex.IsMatch(names[i]) && dir.GetFiles(names[i]).Length != 1) ftp.Delete(names[i]); i++; } foreach (DirectoryInfo subdir in dir.GetDirectories()) { if (!stringSearch(names, subdir.Name)) ftp.MkDir(subdir.Name); ftp.ChDir(subdir.Name); backup(ftp, subdir, regex, getDataKey(ref key, subdir.Name)); ftp.ChDir(".."); } foreach (FileInfo file in dir.GetFiles()) { if (!regex.IsMatch(file.Name)) continue; if (file.LastWriteTime > getDateTime(key.GetValue(file.Name, "0001-01-01 00:00:00").ToString())) { ftp.Put(file.FullName, file.Name, false); key.SetValue(file.Name, DateTime.Now.ToString()); } } }