/// <summary> /// 指定パスのファイルをS3にコピーする /// </summary> /// <param name="filename"></param> private void CopyFile(string filename, int max, int index) { // S3上での名前 var filekey = procDirectoryName(filename); var fileinfo = new FileInfo(filename); DateTime lastModified = DateTime.MaxValue; var response = findS3(filekey); if (null != response) { lastModified = response.LastModified; } // 全コピーモードか、S3上にファイルが無いか、S3上のファイルより新しい場合にアップロード if (option.RunMode == Options.Mode.All || null == response || fileinfo.LastWriteTimeUtc > lastModified) { var request = new TransferUtilityUploadRequest { BucketName = this.Bucket, FilePath = filename, Key = filekey, }; if (!OnlyCount) { transferUtility.Upload(request); } Console.WriteLine("[{1:###,###}/{2:###,###}] Copied...{0}", filename, index, max); CopiedFiles.Add(filename); } else { Console.WriteLine("[{1:###,###}/{2:###,###}] Skip...{0}", filename, index, max); } }
private void retrieveFile(S3Object o, string filename) { DateTime lastModified = o.LastModified; FileInfo fi = null; if (File.Exists(filename)) { fi = new FileInfo(filename); if (fi.LastWriteTime < lastModified) { if (!OnlyCount) { transferUtility.Download(filename, Bucket, o.Key); } Console.WriteLine("Update.. {0}", filename); CopiedFiles.Add(filename); } else { // Console.WriteLine("Skip.... {0}", filename); } } else { if (!OnlyCount) { transferUtility.Download(filename, Bucket, o.Key); } Console.WriteLine("Create.. {0}", filename); CopiedFiles.Add(filename); } /// カウントモードでなければ、タイムスタンプを再設定する fi = new FileInfo(filename); if (lastModified != DateTime.MinValue && !OnlyCount) { fi.LastWriteTime = lastModified; } }