/******************************************************************************* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"). You may not use * this file except in compliance with the License. A copy of the License is located at * * http://aws.amazon.com/apache2.0 * * or in the "license" file accompanying this file. * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * ***************************************************************************** * __ _ _ ___ * ( )( \/\/ )/ __) * /__\ \ / \__ \ * (_)(_) \/\/ (___/ * * AWS SDK for .NET * API Version: 2006-03-01 * */ using System; using System.Collections.Generic; using System.IO; using System.Text; using System.Threading; using Amazon.Runtime.Internal.Util; using Amazon.S3.Model; using Amazon.S3.Transfer.Internal; using Amazon.Util; using System.Globalization; namespace Amazon.S3.Transfer { /// /// /// Provides a high level utility for managing transfers to and from Amazon S3. /// /// /// TransferUtility provides a simple API for /// uploading content to and downloading content /// from Amazon S3. It makes extensive use of Amazon S3 multipart uploads to /// achieve enhanced throughput, performance, and reliability. /// /// /// When uploading large files by specifying file paths instead of a stream, /// TransferUtility uses multiple threads to upload /// multiple parts of a single upload at once. When dealing with large content /// sizes and high bandwidth, this can increase throughput significantly. /// /// /// /// /// Transfers are stored in memory. If the application is restarted, /// previous transfers are no longer accessible. In this situation, if necessary, /// you should clean up any multipart uploads that are incomplete. /// /// public partial interface ITransferUtility : IDisposable { #region UploadDirectory /// /// Uploads files from a specified directory. /// The object key is derived from the file names /// inside the directory. /// For large uploads, the file will be divided and uploaded in parts using /// Amazon S3's multipart API. The parts will be reassembled as one object in /// Amazon S3. /// /// /// /// If you are uploading large files, TransferUtility will use multipart upload to fulfill the request. /// If a multipart upload is interrupted, TransferUtility will attempt to abort the multipart upload. /// Under certain circumstances (network outage, power failure, etc.), TransferUtility will not be able /// to abort the multipart upload. In this case, in order to stop getting charged for the storage of uploaded parts, /// you should manually invoke TransferUtility.AbortMultipartUploads() to abort the incomplete multipart uploads. /// /// /// /// The source directory, that is, the directory containing the files to upload. /// /// /// The target Amazon S3 bucket, that is, the name of the bucket to upload the files to. /// void UploadDirectory(string directory, string bucketName); /// /// Uploads files from a specified directory. /// The object key is derived from the file names /// inside the directory. /// For large uploads, the file will be divided and uploaded in parts using /// Amazon S3's multipart API. The parts will be reassembled as one object in /// Amazon S3. /// /// /// /// If you are uploading large files, TransferUtility will use multipart upload to fulfill the request. /// If a multipart upload is interrupted, TransferUtility will attempt to abort the multipart upload. /// Under certain circumstances (network outage, power failure, etc.), TransferUtility will not be able /// to abort the multipart upload. In this case, in order to stop getting charged for the storage of uploaded parts, /// you should manually invoke TransferUtility.AbortMultipartUploads() to abort the incomplete multipart uploads. /// /// /// /// The source directory, that is, the directory containing the files to upload. /// /// /// The target Amazon S3 bucket, that is, the name of the bucket to upload the files to. /// /// /// A pattern used to identify the files from the source directory to upload. /// /// /// A search option that specifies whether to recursively search for files to upload /// in subdirectories. /// void UploadDirectory(string directory, string bucketName, string searchPattern, SearchOption searchOption); /// /// Uploads files from a specified directory. /// The object key is derived from the file names /// inside the directory. /// For large uploads, the file will be divided and uploaded in parts using /// Amazon S3's multipart API. The parts will be reassembled as one object in /// Amazon S3. /// /// /// /// If you are uploading large files, TransferUtility will use multipart upload to fulfill the request. /// If a multipart upload is interrupted, TransferUtility will attempt to abort the multipart upload. /// Under certain circumstances (network outage, power failure, etc.), TransferUtility will not be able /// to abort the multipart upload. In this case, in order to stop getting charged for the storage of uploaded parts, /// you should manually invoke TransferUtility.AbortMultipartUploads() to abort the incomplete multipart uploads. /// /// /// /// The request that contains all the parameters required to upload a directory. /// void UploadDirectory(TransferUtilityUploadDirectoryRequest request); /// /// Initiates the asynchronous execution of the UploadDirectory operation. /// /// /// /// /// If you are uploading large files, TransferUtility will use multipart upload to fulfill the request. /// If a multipart upload is interrupted, TransferUtility will attempt to abort the multipart upload. /// Under certain circumstances (network outage, power failure, etc.), TransferUtility will not be able /// to abort the multipart upload. In this case, in order to stop getting charged for the storage of uploaded parts, /// you should manually invoke TransferUtility.AbortMultipartUploads() to abort the incomplete multipart uploads. /// /// /// /// The source directory, that is, the directory containing the files to upload. /// /// /// The target Amazon S3 bucket, that is, the name of the bucket to upload the files to. /// /// An AsyncCallback delegate that is invoked when the operation completes. /// A user-defined state object that is passed to the callback procedure. /// Retrieve this object from within the callback procedure using the AsyncState property. /// /// /// /// /// An IAsyncResult that can be used to poll, or wait for results, or both. /// This value is also needed when invoking EndUploadDirectory. IAsyncResult BeginUploadDirectory(string directory, string bucketName, AsyncCallback callback, object state); /// /// Initiates the asynchronous execution of the UploadDirectory operation. /// /// /// /// /// If you are uploading large files, TransferUtility will use multipart upload to fulfill the request. /// If a multipart upload is interrupted, TransferUtility will attempt to abort the multipart upload. /// Under certain circumstances (network outage, power failure, etc.), TransferUtility will not be able /// to abort the multipart upload. In this case, in order to stop getting charged for the storage of uploaded parts, /// you should manually invoke TransferUtility.AbortMultipartUploads() to abort the incomplete multipart uploads. /// /// /// /// The source directory, that is, the directory containing the files to upload. /// /// /// The target Amazon S3 bucket, that is, the name of the bucket to upload the files to. /// /// /// A pattern used to identify the files from the source directory to upload. /// /// /// A search option that specifies whether to recursively search for files to upload /// in subdirectories. /// /// An AsyncCallback delegate that is invoked when the operation completes. /// A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback procedure using the AsyncState property. /// /// /// /// An IAsyncResult that can be used to poll, or wait for results, or both. /// This value is also needed when invoking EndUploadDirectory. IAsyncResult BeginUploadDirectory(string directory, string bucketName, string searchPattern, SearchOption searchOption, AsyncCallback callback, object state); /// /// Initiates the asynchronous execution of the UploadDirectory operation. /// /// /// /// /// If you are uploading large files, TransferUtility will use multipart upload to fulfill the request. /// If a multipart upload is interrupted, TransferUtility will attempt to abort the multipart upload. /// Under certain circumstances (network outage, power failure, etc.), TransferUtility will not be able /// to abort the multipart upload. In this case, in order to stop getting charged for the storage of uploaded parts, /// you should manually invoke TransferUtility.AbortMultipartUploads() to abort the incomplete multipart uploads. /// /// /// /// The request that contains all the parameters required to upload a directory. /// /// An AsyncCallback delegate that is invoked when the operation completes. /// A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback procedure using the AsyncState property. /// /// /// /// An IAsyncResult that can be used to poll, or wait for results, or both. /// This value is also needed when invoking EndUploadDirectory. IAsyncResult BeginUploadDirectory(TransferUtilityUploadDirectoryRequest request, AsyncCallback callback, object state); /// /// Finishes the asynchronous execution of the UploadDirectory operation. /// /// /// The IAsyncResult returned by the call to BeginUploadDirectory. /// /// /// void EndUploadDirectory(IAsyncResult asyncResult); #endregion #region Upload /// /// Uploads the specified file. /// The object key is derived from the file's name. /// Multiple threads are used to read the file and perform multiple uploads in parallel. /// For large uploads, the file will be divided and uploaded in parts using /// Amazon S3's multipart API. The parts will be reassembled as one object in /// Amazon S3. /// /// /// /// If you are uploading large files, TransferUtility will use multipart upload to fulfill the request. /// If a multipart upload is interrupted, TransferUtility will attempt to abort the multipart upload. /// Under certain circumstances (network outage, power failure, etc.), TransferUtility will not be able /// to abort the multipart upload. In this case, in order to stop getting charged for the storage of uploaded parts, /// you should manually invoke TransferUtility.AbortMultipartUploads() to abort the incomplete multipart uploads. /// /// /// /// The file path of the file to upload. /// /// /// The target Amazon S3 bucket, that is, the name of the bucket to upload the file to. /// void Upload(string filePath, string bucketName); /// /// Uploads the specified file. /// Multiple threads are used to read the file and perform multiple uploads in parallel. /// For large uploads, the file will be divided and uploaded in parts using /// Amazon S3's multipart API. The parts will be reassembled as one object in /// Amazon S3. /// /// /// /// If you are uploading large files, TransferUtility will use multipart upload to fulfill the request. /// If a multipart upload is interrupted, TransferUtility will attempt to abort the multipart upload. /// Under certain circumstances (network outage, power failure, etc.), TransferUtility will not be able /// to abort the multipart upload. In this case, in order to stop getting charged for the storage of uploaded parts, /// you should manually invoke TransferUtility.AbortMultipartUploads() to abort the incomplete multipart uploads. /// /// /// /// The file path of the file to upload. /// /// /// The target Amazon S3 bucket, that is, the name of the bucket to upload the file to. /// /// /// The key under which the Amazon S3 object is stored. /// void Upload(string filePath, string bucketName, string key); /// /// Uploads the contents of the specified stream. /// For large uploads, the file will be divided and uploaded in parts using /// Amazon S3's multipart API. The parts will be reassembled as one object in /// Amazon S3. /// /// /// /// If you are uploading large files, TransferUtility will use multipart upload to fulfill the request. /// If a multipart upload is interrupted, TransferUtility will attempt to abort the multipart upload. /// Under certain circumstances (network outage, power failure, etc.), TransferUtility will not be able /// to abort the multipart upload. In this case, in order to stop getting charged for the storage of uploaded parts, /// you should manually invoke TransferUtility.AbortMultipartUploads() to abort the incomplete multipart uploads. /// /// /// /// The stream to read to obtain the content to upload. /// /// /// The target Amazon S3 bucket, that is, the name of the bucket to upload the stream to. /// /// /// The key under which the Amazon S3 object is stored. /// void Upload(Stream stream, string bucketName, string key); /// /// Uploads the file or stream specified by the request. /// To track the progress of the upload, /// add an event listener to the request's UploadProgressEvent. /// For large uploads, the file will be divided and uploaded in parts using /// Amazon S3's multipart API. The parts will be reassembled as one object in /// Amazon S3. /// /// /// /// If you are uploading large files, TransferUtility will use multipart upload to fulfill the request. /// If a multipart upload is interrupted, TransferUtility will attempt to abort the multipart upload. /// Under certain circumstances (network outage, power failure, etc.), TransferUtility will not be able /// to abort the multipart upload. In this case, in order to stop getting charged for the storage of uploaded parts, /// you should manually invoke TransferUtility.AbortMultipartUploads() to abort the incomplete multipart uploads. /// /// /// /// Contains all the parameters required to upload to Amazon S3. /// void Upload(TransferUtilityUploadRequest request); /// /// Initiates the asynchronous execution of the Upload operation. /// /// /// /// /// If you are uploading large files, TransferUtility will use multipart upload to fulfill the request. /// If a multipart upload is interrupted, TransferUtility will attempt to abort the multipart upload. /// Under certain circumstances (network outage, power failure, etc.), TransferUtility will not be able /// to abort the multipart upload. In this case, in order to stop getting charged for the storage of uploaded parts, /// you should manually invoke TransferUtility.AbortMultipartUploads() to abort the incomplete multipart uploads. /// /// /// /// The file path of the file to upload. /// /// /// The target Amazon S3 bucket, that is, the name of the bucket to upload the file to. /// /// An AsyncCallback delegate that is invoked when the operation completes. /// A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback procedure using the AsyncState property. /// /// /// /// An IAsyncResult that can be used to poll, or wait for results, or both. /// This values is also needed when invoking EndUpload. IAsyncResult BeginUpload(string filePath, string bucketName, AsyncCallback callback, object state); /// /// Initiates the asynchronous execution of the Upload operation. /// /// /// /// /// If you are uploading large files, TransferUtility will use multipart upload to fulfill the request. /// If a multipart upload is interrupted, TransferUtility will attempt to abort the multipart upload. /// Under certain circumstances (network outage, power failure, etc.), TransferUtility will not be able /// to abort the multipart upload. In this case, in order to stop getting charged for the storage of uploaded parts, /// you should manually invoke TransferUtility.AbortMultipartUploads() to abort the incomplete multipart uploads. /// /// /// /// The file path of the file to upload. /// /// /// The target Amazon S3 bucket, that is, the name of the bucket to upload the file to. /// /// /// The key under which the Amazon S3 object is stored. /// /// An AsyncCallback delegate that is invoked when the operation completes. /// A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback procedure using the AsyncState property. /// /// /// /// An IAsyncResult that can be used to poll, or wait for results, or both. /// This values is also needed when invoking EndUpload. IAsyncResult BeginUpload(string filePath, string bucketName, string key, AsyncCallback callback, object state); /// /// Initiates the asynchronous execution of the Upload operation. /// /// /// /// /// If you are uploading large files, TransferUtility will use multipart upload to fulfill the request. /// If a multipart upload is interrupted, TransferUtility will attempt to abort the multipart upload. /// Under certain circumstances (network outage, power failure, etc.), TransferUtility will not be able /// to abort the multipart upload. In this case, in order to stop getting charged for the storage of uploaded parts, /// you should manually invoke TransferUtility.AbortMultipartUploads() to abort the incomplete multipart uploads. /// /// /// /// The stream to read to obtain the content to upload. /// /// /// The target Amazon S3 bucket, that is, the name of the bucket to upload the stream to. /// /// /// The key under which the Amazon S3 object is stored. /// /// An AsyncCallback delegate that is invoked when the operation completes. /// A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback procedure using the AsyncState property. /// /// /// /// An IAsyncResult that can be used to poll, or wait for results, or both. /// This values is also needed when invoking EndUpload. IAsyncResult BeginUpload(Stream stream, string bucketName, string key, AsyncCallback callback, object state); /// /// Initiates the asynchronous execution of the Upload operation. /// /// /// /// /// If you are uploading large files, TransferUtility will use multipart upload to fulfill the request. /// If a multipart upload is interrupted, TransferUtility will attempt to abort the multipart upload. /// Under certain circumstances (network outage, power failure, etc.), TransferUtility will not be able /// to abort the multipart upload. In this case, in order to stop getting charged for the storage of uploaded parts, /// you should manually invoke TransferUtility.AbortMultipartUploads() to abort the incomplete multipart uploads. /// /// /// /// Contains all the parameters required to upload to Amazon S3. /// /// An AsyncCallback delegate that is invoked when the operation completes. /// A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback procedure using the AsyncState property. /// /// /// /// An IAsyncResult that can be used to poll, or wait for results, or both. /// This values is also needed when invoking EndUpload. IAsyncResult BeginUpload(TransferUtilityUploadRequest request, AsyncCallback callback, object state); /// /// Finishes the asynchronous execution of the Upload operation. /// /// /// The IAsyncResult returned by the call to BeginUpload. /// /// /// void EndUpload(IAsyncResult asyncResult); #endregion #region OpenStream /// /// Returns a stream from which the caller can read the content from the specified /// Amazon S3 bucket and key. /// The caller of this method is responsible for closing the stream. /// /// /// The name of the bucket. /// /// /// The object key. /// /// /// A stream of the contents from the specified Amazon S3 and key. /// Stream OpenStream(string bucketName, string key); /// /// Returns a stream to read the contents from Amazon S3 as /// specified by the TransferUtilityOpenStreamRequest. /// The caller of this method is responsible for closing the stream. /// /// /// Contains all the parameters required to open a stream to an S3 object. /// /// /// A stream of the contents from Amazon S3. /// Stream OpenStream(TransferUtilityOpenStreamRequest request); /// /// Initiates the asynchronous execution of the OpenStream operation. /// /// /// /// The name of the bucket. /// /// /// The object key. /// /// An AsyncCallback delegate that is invoked when the operation completes. /// A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback procedure using the AsyncState property. /// /// /// /// An IAsyncResult that can be used to poll, or wait for results, or both. /// This values is also needed when invoking EndOpenStream. IAsyncResult BeginOpenStream(string bucketName, string key, AsyncCallback callback, object state); /// /// Initiates the asynchronous execution of the OpenStream operation. /// /// /// /// Contains all the parameters required to open a stream to an Amazon S3 object. /// /// An AsyncCallback delegate that is invoked when the operation completes. /// A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback procedure using the AsyncState property. /// /// /// /// An IAsyncResult that can be used to poll, or wait for results, or both. /// This values is also needed when invoking EndOpenStream. IAsyncResult BeginOpenStream(TransferUtilityOpenStreamRequest request, AsyncCallback callback, object state); /// /// Finishes the asynchronous execution of the OpenStream operation. /// /// /// The IAsyncResult returned by the call to BeginOpenStream. /// /// /// Stream EndOpenStream(IAsyncResult asyncResult); #endregion #region Download /// /// Downloads the content from Amazon S3 and writes it to the specified file. /// /// /// The file path where the content from Amazon S3 will be written to. /// /// /// The name of the bucket containing the Amazon S3 object to download. /// /// /// The key under which the Amazon S3 object is stored. /// void Download(string filePath, string bucketName, string key); /// /// 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 used as the key name. /// /// /// Contains all the parameters required to download an Amazon S3 object. /// void Download(TransferUtilityDownloadRequest request); /// /// Initiates the asynchronous execution of the Download operation. /// /// /// /// The file path where the content from Amazon S3 will be written to. /// /// /// The name of the bucket containing the Amazon S3 object to download. /// /// /// The key under which the Amazon S3 object is stored. /// /// An AsyncCallback delegate that is invoked when the operation completes. /// A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback procedure using the AsyncState property. /// /// /// /// An IAsyncResult that can be used to poll, or wait for results, or both. /// This values is also needed when invoking EndDownload. IAsyncResult BeginDownload(string filePath, string bucketName, string key, AsyncCallback callback, object state); /// /// Initiates the asynchronous execution of the Download operation. /// /// /// /// Contains all the parameters required to download an Amazon S3 object. /// /// An AsyncCallback delegate that is invoked when the operation completes. /// A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback procedure using the AsyncState property. /// /// /// /// An IAsyncResult that can be used to poll, or wait for results, or both. /// This values is also needed when invoking EndDownload. IAsyncResult BeginDownload(TransferUtilityDownloadRequest request, AsyncCallback callback, object state); /// /// Finishes the asynchronous execution of the Download operation. /// /// /// The IAsyncResult returned by the call to BeginDownload. /// /// /// void EndDownload(IAsyncResult asyncResult); #endregion #region DownloadDirectory /// /// Downloads the objects in Amazon S3 that have a key that starts with the value /// specified by s3Directory. /// /// /// The name of the bucket containing the Amazon S3 objects to download. /// /// /// The directory in Amazon S3 to download. /// /// /// The local directory to download the objects to. /// void DownloadDirectory(string bucketName, string s3Directory, string localDirectory); /// /// Downloads the objects in Amazon S3 that have a key that starts with the value /// specified by the S3Directory /// property of the passed in TransferUtilityDownloadDirectoryRequest object. /// /// /// Contains all the parameters required to download objects from Amazon S3 /// into a local directory. /// void DownloadDirectory(TransferUtilityDownloadDirectoryRequest request); /// /// Initiates the asynchronous execution of the DownloadDirectory operation. /// /// /// /// The name of the bucket containing the Amazon S3 objects to download. /// /// /// The directory in Amazon S3 to download. /// /// /// The local directory to download the objects to. /// /// An AsyncCallback delegate that is invoked when the operation completes. /// A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback procedure using the AsyncState property. /// /// /// /// An IAsyncResult that can be used to poll, or wait for results, or both. /// This values is also needed when invoking EndDownloadDirectory. IAsyncResult BeginDownloadDirectory(string bucketName, string s3Directory, string localDirectory, AsyncCallback callback, object state); /// /// Initiates the asynchronous execution of the DownloadDirectory operation. /// /// /// /// Contains all the parameters required to download objects from a directory in Amazon S3 /// to a local directory. /// /// An AsyncCallback delegate that is invoked when the operation completes. /// A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback procedure using the AsyncState property. /// /// /// /// An IAsyncResult that can be used to poll, or wait for results, or both. /// This values is also needed when invoking EndDownload. IAsyncResult BeginDownloadDirectory(TransferUtilityDownloadDirectoryRequest request, AsyncCallback callback, object state); /// /// Finishes the asynchronous execution of the DownloadDirectory operation. /// /// /// The IAsyncResult returned by the call to BeginDownloadDirectory. /// /// /// void EndDownloadDirectory(IAsyncResult asyncResult); #endregion #region AbortMultipartUploads /// /// Aborts the multipart uploads that were initiated before the specified date. /// /// /// The name of the bucket containing multipart uploads. /// /// /// The date before which the multipart uploads were initiated. /// void AbortMultipartUploads(string bucketName, DateTime initiatedDate); /// /// Initiates the asynchronous execution of the AbortMultipartUploads operation. /// /// /// /// The name of the bucket containing multipart uploads. /// /// /// The date before which the multipart uploads were initiated. /// /// An AsyncCallback delegate that is invoked when the operation completes. /// A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback procedure using the AsyncState property. /// /// /// /// An IAsyncResult that can be used to poll, or wait for results, or both. /// This values is also needed when invoking EndAbortMultipartUploads. IAsyncResult BeginAbortMultipartUploads(string bucketName, DateTime initiatedDate, AsyncCallback callback, object state); /// /// Finishes the asynchronous execution of the AbortMultipartUploads operation. /// /// /// The IAsyncResult returned by the call to BeginAbortMultipartUploads. /// /// /// void EndAbortMultipartUploads(IAsyncResult asyncResult); #endregion } }