public override void Execute()
        {
            ValidateRequest();
            EnsureDirectoryExists(new DirectoryInfo(this._request.LocalDirectory));

            ListObjectsRequest listRequest = ConstructListObjectRequest();

            List <S3Object> objs = new List <S3Object>();

            do
            {
                ListObjectsResponse listResponse = this._s3Client.ListObjects(listRequest);
                foreach (S3Object s3o in listResponse.S3Objects)
                {
                    if (this._request.IsSetModifiedSinceDate() && s3o.LastModified <= this._request.ModifiedSinceDate)
                    {
                        continue;
                    }
                    if (this._request.IsSetUnmodifiedSinceDate() && s3o.LastModified > this._request.UnmodifiedSinceDate)
                    {
                        continue;
                    }

                    this._totalBytes += s3o.Size;
                    objs.Add(s3o);
                }
                listRequest.Marker = listResponse.NextMarker;
            } while (!string.IsNullOrEmpty(listRequest.Marker));

            this._totalNumberOfFilesToDownload = objs.Count;

            foreach (S3Object s3o in objs)
            {
                if (s3o.Key.EndsWith("/", StringComparison.Ordinal))
                {
                    continue;
                }

                this._currentFile = s3o.Key.Substring(listRequest.Prefix.Length);

                var             downloadRequest = ConstructTransferUtilityDownloadRequest(s3o, listRequest.Prefix.Length);
                DownloadCommand command         = new DownloadCommand(this._s3Client, downloadRequest);
                command.Execute();
            }
        }
        public override void Execute()
        {
            ValidateRequest();
            EnsureDirectoryExists(new DirectoryInfo(this._request.LocalDirectory));

            ListObjectsRequest listRequest = ConstructListObjectRequest();

            List<S3Object> objs = new List<S3Object>();
            do
            {
                ListObjectsResponse listResponse = this._s3Client.ListObjects(listRequest);
                foreach (S3Object s3o in listResponse.S3Objects)
                {
                    if (this._request.IsSetModifiedSinceDate() && s3o.LastModified <= this._request.ModifiedSinceDate)
                        continue;
                    if (this._request.IsSetUnmodifiedSinceDate() && s3o.LastModified > this._request.UnmodifiedSinceDate)
                        continue;

                    this._totalBytes += s3o.Size;
					objs.Add(s3o);
                }
                listRequest.Marker = listResponse.NextMarker;
            } while (!string.IsNullOrEmpty(listRequest.Marker));
			
            this._totalNumberOfFilesToDownload = objs.Count;

            foreach (S3Object s3o in objs)
            {
                if (s3o.Key.EndsWith("/", StringComparison.Ordinal))
                    continue;

                this._currentFile = s3o.Key.Substring(listRequest.Prefix.Length);

                var downloadRequest = ConstructTransferUtilityDownloadRequest(s3o, listRequest.Prefix.Length);
                DownloadCommand command = new DownloadCommand(this._s3Client, downloadRequest);
                command.Execute();
        }
        }
Exemplo n.º 3
0
 /// <summary>
 /// 	Downloads the content from Amazon S3 and writes it to the specified file.    
 /// 	If the key is not specified in the request parameter,
 /// 	the file name will be assumed.
 /// </summary>
 /// <param name="request">
 /// 	Contains all the parameters used to download an Amazon S3 object.
 /// </param>
 public void Download(TransferUtilityDownloadRequest request)
 {
     BaseCommand command = new DownloadCommand(this._s3Client, request);
     command.Execute();
 }
        public override void Execute()
        {
            if (!this._request.IsSetBucketName())
            {
                throw new ArgumentNullException("BucketName", "The bucketName Specified is null or empty!");
            }
            if (!this._request.IsSetS3Directory())
            {
                throw new ArgumentNullException("S3Directory", "The S3Directory Specified is null or empty!");
            }
            if (!this._request.IsSetLocalDirectory())
            {
                throw new ArgumentNullException("LocalDirectory", "The LocalDirectory Specified is null or empty!");
            }

            if (File.Exists(this._request.S3Directory))
            {
                throw new ArgumentNullException("LocalDirectory", "A file already exists with the same name indicated by LocalDirectory!");
            }

            EnsureDirectoryExists(new DirectoryInfo(this._request.LocalDirectory));

            ListObjectsRequest listRequest = new ListObjectsRequest();

            listRequest.BucketName = this._request.BucketName;
            listRequest.Prefix     = this._request.S3Directory;

            listRequest.Prefix = listRequest.Prefix.Replace('\\', '/');
            if (!listRequest.Prefix.EndsWith("/"))
            {
                listRequest.Prefix += "/";
            }

            if (listRequest.Prefix.StartsWith("/"))
            {
                if (listRequest.Prefix.Length == 1)
                {
                    listRequest.Prefix = "";
                }
                else
                {
                    listRequest.Prefix = listRequest.Prefix.Substring(1);
                }
            }

            List <S3Object> objs = new List <S3Object>();

            do
            {
                ListObjectsResponse listResponse = this._s3Client.ListObjects(listRequest);
                foreach (S3Object s3o in listResponse.S3Objects)
                {
                    DateTime lastModified = DateTime.Parse(s3o.LastModified);
                    if (this._request.IsSetModifiedSinceDate() && this._request.ModifiedSinceDate < lastModified)
                    {
                        continue;
                    }
                    if (this._request.IsSetUnmodifiedSinceDate() && lastModified < this._request.UnmodifiedSinceDate)
                    {
                        continue;
                    }

                    objs.Add(s3o);
                }
                listRequest.Marker = listResponse.NextMarker;
            } while (!string.IsNullOrEmpty(listRequest.Marker));

            this._totalNumberOfFilesToDownload = objs.Count;

            foreach (S3Object s3o in objs)
            {
                if (s3o.Key.EndsWith("/"))
                {
                    continue;
                }

                this._currentFile = s3o.Key.Substring(listRequest.Prefix.Length);

                TransferUtilityDownloadRequest downloadRequest = new TransferUtilityDownloadRequest();
                downloadRequest.BucketName = this._request.BucketName;
                downloadRequest.Key        = s3o.Key;
                downloadRequest.FilePath   = Path.Combine(this._request.LocalDirectory, this._currentFile);
                downloadRequest.Timeout    = this._request.Timeout;
                downloadRequest.WriteObjectProgressEvent += new EventHandler <WriteObjectProgressArgs>(downloadedProgressEventCallback);


                DownloadCommand command = new DownloadCommand(this._s3Client, downloadRequest);
                command.Execute();

                this._numberOfFilesDownloaded++;
            }
        }
        public override void Execute()
        {
            if (!this._request.IsSetBucketName())
            {
                throw new ArgumentNullException("BucketName", "The bucketName Specified is null or empty!");
            }
            if (!this._request.IsSetS3Directory())
            {
                throw new ArgumentNullException("S3Directory", "The S3Directory Specified is null or empty!");
            }
            if (!this._request.IsSetLocalDirectory())
            {
                throw new ArgumentNullException("LocalDirectory", "The LocalDirectory Specified is null or empty!");
            }

            if (File.Exists(this._request.S3Directory))
            {
                throw new ArgumentNullException("LocalDirectory", "A file already exists with the same name indicated by LocalDirectory!");
            }

            EnsureDirectoryExists(new DirectoryInfo(this._request.LocalDirectory));

            ListObjectsRequest listRequest = new ListObjectsRequest();
            listRequest.BucketName = this._request.BucketName;
            listRequest.Prefix = this._request.S3Directory;

            listRequest.Prefix = listRequest.Prefix.Replace('\\', '/');
            if (!listRequest.Prefix.EndsWith("/"))
                listRequest.Prefix += "/";

            if (listRequest.Prefix.StartsWith("/"))
            {
                if (listRequest.Prefix.Length == 1)
                    listRequest.Prefix = "";
                else
                    listRequest.Prefix = listRequest.Prefix.Substring(1);
            }

            ListObjectsResponse listResponse = this._s3Client.ListObjects(listRequest);
            List<S3Object> objs = new List<S3Object>();
            foreach (S3Object s3o in listResponse.S3Objects)
            {
                DateTime lastModified = DateTime.Parse(s3o.LastModified);
                if (this._request.IsSetModifiedSinceDate() && this._request.ModifiedSinceDate < lastModified)
                    continue;
                if (this._request.IsSetUnmodifiedSinceDate() && lastModified < this._request.UnmodifiedSinceDate)
                    continue;

                objs.Add(s3o);
            }

            this._totalNumberOfFilesToDownload = objs.Count;

            foreach (S3Object s3o in objs)
            {
                this._currentFile = s3o.Key.Substring(listRequest.Prefix.Length);

                TransferUtilityDownloadRequest downloadRequest = new TransferUtilityDownloadRequest();
                downloadRequest.BucketName = this._request.BucketName;
                downloadRequest.Key = s3o.Key;
                downloadRequest.FilePath = Path.Combine(this._request.LocalDirectory, this._currentFile);
                downloadRequest.Timeout = this._request.Timeout;
                downloadRequest.WithSubscriber(new EventHandler<WriteObjectProgressArgs>(downloadedProgressEventCallback));

                DownloadCommand command = new DownloadCommand(this._s3Client, downloadRequest);
                command.Execute();

                this._numberOfFilesDownloaded++;
            }
        }
        public override void Execute()
        {
            if (!this._request.IsSetBucketName())
            {
                throw new InvalidOperationException("The bucketName Specified is null or empty!");
            }
            if (!this._request.IsSetS3Directory())
            {
                throw new InvalidOperationException("The S3Directory Specified is null or empty!");
            }
            if (!this._request.IsSetLocalDirectory())
            {
                throw new InvalidOperationException("The LocalDirectory Specified is null or empty!");
            }

            if (File.Exists(this._request.S3Directory))
            {
                throw new InvalidOperationException("A file already exists with the same name indicated by LocalDirectory!");
            }

            EnsureDirectoryExists(new DirectoryInfo(this._request.LocalDirectory));

            ListObjectsRequest listRequest = new ListObjectsRequest();
            listRequest.BucketName = this._request.BucketName;
            listRequest.Prefix = this._request.S3Directory;

            listRequest.Prefix = listRequest.Prefix.Replace('\\', '/');
            if (!listRequest.Prefix.EndsWith("/", StringComparison.Ordinal))
                listRequest.Prefix += "/";

            if (listRequest.Prefix.StartsWith("/", StringComparison.Ordinal))
            {
                if (listRequest.Prefix.Length == 1)
                    listRequest.Prefix = "";
                else
                    listRequest.Prefix = listRequest.Prefix.Substring(1);
            }

            List<S3Object> objs = new List<S3Object>();
            do
            {
                ListObjectsResponse listResponse = this._s3Client.ListObjects(listRequest);
                foreach (S3Object s3o in listResponse.S3Objects)
                {
					if (this._request.IsSetModifiedSinceDate() && this._request.ModifiedSinceDate < s3o.LastModified)
						continue;
					if (this._request.IsSetUnmodifiedSinceDate() && s3o.LastModified < this._request.UnmodifiedSinceDate)
						continue;

					objs.Add(s3o);
                }
                listRequest.Marker = listResponse.NextMarker;
            } while (!string.IsNullOrEmpty(listRequest.Marker));
			
            this._totalNumberOfFilesToDownload = objs.Count;

            foreach (S3Object s3o in objs)
            {
                if (s3o.Key.EndsWith("/", StringComparison.Ordinal))
                    continue;

                this._currentFile = s3o.Key.Substring(listRequest.Prefix.Length);

                TransferUtilityDownloadRequest downloadRequest = new TransferUtilityDownloadRequest();
                downloadRequest.BucketName = this._request.BucketName;
                downloadRequest.Key = s3o.Key;
                downloadRequest.FilePath = Path.Combine(this._request.LocalDirectory, this._currentFile);
                downloadRequest.WriteObjectProgressEvent += downloadedProgressEventCallback;


                DownloadCommand command = new DownloadCommand(this._s3Client, downloadRequest);
                command.Execute();

                this._numberOfFilesDownloaded++;
            }
        }