CloudStorage Component
Properties Methods Events Configuration Settings Errors
The CloudStorage component provide an easy way to upload, download, and manage files and folders with multiple service providers.
Syntax
nsoftware.InCloudStorage.Cloudstorage
Remarks
The CloudStorage component provides a single interface that can be used to work with a variety of services. By supporting multiple providers with a single API code may be written once and used to support multiple services. The following providers are currently supported by this component:
- Amazon S3
- Box.com
- Dropbox
- Google Drive
- Microsoft OneDrive
- SharePoint Online
The component supports simple file and folder management as well as encryption. Capabilities include uploading and downloading files, strong encryption support, creating folders, and more.
To begin, first create an account and register your application. Consult the documentation of the individual service provider for instructions on this process.
Authentication
The following providers use OAuth 2.0 for authentication:
- Box
- Dropbox
- Google Drive
- Microsoft OneDrive
Use the OAuth component included in the toolkit, or any other OAuth
implementation to perform authentication and retrieve an authorization string. Once you've obtained an
authorization string like:
Bearer ya29.AHES6ZSZEJzATdZYjeihDn5W-VrXSsxEZu5p0pclxGdKKQAssign this value to the Authorization property before attempting any operations. Consult the service provider documentation for more information about supported scope values and more details on OAuth authentication.
To authenticate with Amazon S3 set AccessKey and SecretKey. To authenticate with SharePoint Online set URL, User, and Password.
Selecting a Provider
To specify the provider simply set ServiceProvider. This tells the component to which service requests will be made.
Listing Files and Folders
ListDirectory lists files and folder the path specified by RemotePath.
The directory entries are provided through the DirList event and also via the DirList property.
cloudstorage.RemoteFile = ""; //Clear filemask cloudstorage.RemotePath = "MyFolder"; cloudstorage.ListDirectory(); for (int i = 0; i < cloudstorage.DirList.Count; i++) { Console.WriteLine(cloudstorage.DirList[i].FileName); Console.WriteLine(cloudstorage.DirList[i].FileSize); Console.WriteLine(cloudstorage.DirList[i].FileTime); Console.WriteLine(cloudstorage.DirList[i].IsDir); }
The RemoteFile property may also be used as a filemask when listing files. For instance:
component.RemoteFile = "*.txt" component.ListDirectory()
Note: Since RemoteFile is used as a filemask be sure to clear or reset this value before calling ListDirectory
Downloading Files
The Download method downloads a specific file.
Set RemoteFile to the name the file to download before calling this method. If RemoteFile only specifies a filename it will be downloaded from the path specified by RemotePath. RemoteFile may also be set to an absolute path.
The file will be downloaded to the stream specified (if any) by SetDownloadStream. If a stream is not specified and LocalFile is set the file will be saved to the specified location. If a stream is not specified and LocalFile is not set the file data will be held by ResourceData.
To decrypt an encrypted file set EncryptionAlgorithm and EncryptionPassword before calling this method.
cloudstorage.RemotePath = "My Folder"; cloudstorage.RemoteFile = "MyFile.zip"; cloudstorage.LocalFile = "../MyFile.zip"; cloudstorage.Download();
Resuming Downloads
The component also supports resuming failed downloads by using the StartByte property. If the download was interrupted, set StartByte to the appropriate offset before calling this method to resume the download.
cloudstorage.RemotePath = myRemoteFolder; cloudstorage.RemoteFile = myRemoteFile; cloudstorage.LocalFile = downloadFile; cloudstorage.Download(); //The transfer is interrupted and Download() above fails. Later, resume the download: //Get the size of the partially download file cloudstorage.StartByte = new FileInfo(downloadFile).Length; cloudstorage.RemotePath = myRemoteFolder; cloudstorage.RemoteFile = myRemoteFile; cloudstorage.LocalFile = downloadFile; cloudstorage.Download();
Resuming Encrypted File Downloads
Resuming encrypted file downloads is only supported when LocalFile was set in the initial download attempt. When beginning an encrypted download if LocalFile is set the component will create a temporary file in TempPath to hold the encrypted data until it is complete.
If the download is interrupted DownloadTempFile will be populated with the temporary file holding the partial data.
When resuming, DownloadTempFile must be populated along with StartByte to allow the remainder of the encrypted data
to be downloaded. Once the encrypted data is downloaded it will be decrypted and written to LocalFile.
cloudstorage.RemotePath = myRemoteFolder; cloudstorage.RemoteFile = myRemoteFile; cloudstorage.LocalFile = downloadFile; cloudstorage.EncryptionPassword = "password"; cloudstorage.Download(); //The transfer is interrupted and Download() above fails. Later, resume the download: //Get the size of the partially download temp file cloudstorage.StartByte = new FileInfo(cloudstorage.Config("DownloadTempFile")).Length; cloudstorage.RemotePath = myRemoteFolder; cloudstorage.RemoteFile = myRemoteFile; cloudstorage.LocalFile = downloadFile; cloudstorage.EncryptionPassword = "password"; cloudstorage.Download();
Uploading Files
The Upload method is used to upload files. If SetUploadStream is used to set an upload stream the data to upload is taken from the stream instead.
RemoteFile should be set to either a relative or absolute path. If RemoteFile is not an absolute path it will be uploaded relative to RemotePath.
To encrypt a file before uploading set EncryptionAlgorithm and EncryptionPassword.
Note: Resuming uploads is not currently supported.
Code Example:
//Upload with a relative path cloudstorage.LocalFile = "C:\localfile.txt" cloudstorage.RemoteFile = "remotefile.txt" cloudstorage.Upload() //Upload with an absolute path cloudstorage.LocalFile = "C:\localfile2.txt" cloudstorage.RemoteFile = "/folder/remotefile2.txt" cloudstorage.Upload()
Additional Functionality
The CloudStorage component offers advanced functionality beyond simple uploads and downloads. For instance:
- Encrypt and decrypt files using EncryptionAlgorithm and EncryptionPassword.
- DeleteFile provides a way to delete files.
- MakeDirectory and RemoveDirectory support creating and deleting folders.
- RenameFile allows renaming of existing files on the server.
- And more!
Property List
The following is the full list of the properties of the component with short descriptions. Click on the links for further details.
Account | Account credentials. |
Authorization | OAuth 2.0 Authorization Token. |
DirList | Collection of entries resulting in the last directory listing. |
EncryptionAlgorithm | The encryption algorithm. |
EncryptionPassword | The encryption password. |
Firewall | A set of properties related to firewall access. |
Idle | The current status of the component. |
LocalFile | The location of the local file. |
LocalHost | The name of the local host or user-assigned IP interface through which connections are initiated or accepted. |
Overwrite | Whether to overwrite the local or remote file. |
Proxy | A set of properties related to proxy access. |
RemoteFile | The name of the remote file. |
RemotePath | The current path on the server. |
ServiceProvider | The storage service provider. |
SSLAcceptServerCert | Instructs the component to unconditionally accept the server certificate that matches the supplied certificate. |
SSLCert | The certificate to be used during SSL negotiation. |
SSLServerCert | The server certificate for the last established connection. |
StartByte | The byte offset from which to start download. |
Timeout | A timeout for the component. |
Method List
The following is the full list of the methods of the component with short descriptions. Click on the links for further details.
Config | Sets or retrieves a configuration setting . |
DeleteFile | Remove a file specified by FileName from the server. |
Download | Download the specified file. |
Interrupt | Interrupt the current method. |
ListDirectory | Lists the current directory specified by RemotePath on the server. |
MakeDirectory | Creates a directory on the server. |
RemoveDirectory | Remove the specified directory. |
RenameFile | Renames the file. |
Upload | Uploads the file specified by LocalFile to the server. |
Event List
The following is the full list of the events fired by the component with short descriptions. Click on the links for further details.
DirList | Fired when a directory entry is received. |
EndTransfer | Fired when a document finishes transferring. |
Error | Information about errors during data delivery. |
SSLServerAuthentication | Fired after the server presents its certificate to the client. |
SSLStatus | Shows the progress of the secure connection. |
StartTransfer | Fired when a document starts transferring (after the headers). |
Transfer | Fired while a document transfers (delivers document). |
Configuration Settings
The following is a list of configuration settings for the component with short descriptions. Click on the links for further details.
DateFormat | The date format of the file time. |
DownloadTempFile | The temporary file used when downloading encrypted data. |
EncryptionIV | The initialization vector to be used for encryption/decryption. |
EncryptionKey | The key to use during encryption/decryption. |
XPath | Provides a way to point to a specific element in the returned XML response. |
XElement | The name of the current element. |
XParent | The parent of the current element. |
XSubTree | A snapshot of the current element in the document. |
XText | The text of the current element. |
XChildCount | The number of child elements of the current element. |
XChildName[x] | The name of the child element. |
XChildXText[x] | The inner text of the child element. |
TempPath | The path to the directory where temporary files are created. |
AcceptEncoding | Used to tell the server which types of content encodings the client supports. |
AllowHTTPCompression | This property enables HTTP compression for receiving data. |
AllowIdenticalRedirectURL | Allow redirects to the same URL. |
Append | Whether to append data to LocalFile. |
Authorization | The Authorization string to be sent to the server. |
BytesTransferred | Contains the number of bytes transferred in the response data. |
EncodeURL | If set to true the URL will be encoded by the component. |
FollowRedirects | Determines what happens when the server issues a redirect. |
GetOn302Redirect | If set to true the component will perform a GET on the new location. |
HTTPVersion | The version of HTTP used by the component. |
IfModifiedSince | A date determining the maximum age of the desired document. |
KeepAlive | Determines whether the HTTP connection is closed after completion of the request. |
MaxRedirectAttempts | Limits the number of redirects that are followed in a request. |
OtherHeaders | Other headers as determined by the user (optional). |
ProxyAuthorization | The authorization string to be sent to the proxy server. |
ProxyAuthScheme | The authorization scheme to be used for the proxy. |
ProxyPassword | A password if authentication is to be used for the proxy. |
ProxyPort | Port for the proxy server (default 80). |
ProxyServer | Name or IP address of a proxy server (optional). |
ProxyUser | A user name if authentication is to be used for the proxy. |
TransferredDataLimit | The maximum number of incoming bytes to be stored by the component. |
TransferredHeaders | The full set of headers as received from the server. |
UseChunkedEncoding | Enables or Disables HTTP chunked encoding for transfers. |
ChunkSize | Specifies the chunk size in bytes when using chunked encoding. |
UserAgent | Information about the user agent (browser). |
KerberosSPN | The Service Principal Name for the Kerberos Domain Controller. |
ConnectionTimeout | Sets a separate timeout value for establishing a connection. |
FirewallAutoDetect | Tells the component whether or not to automatically detect and use firewall system settings, if available. |
FirewallHost | Name or IP address of firewall (optional). |
FirewallPassword | Password to be used if authentication is to be used when connecting through the firewall. |
FirewallPort | The TCP port for the FirewallHost;. |
FirewallType | Determines the type of firewall to connect through. |
FirewallUser | A user name if authentication is to be used connecting through a firewall. |
KeepAliveTime | The inactivity time in milliseconds before a TCP keep-alive packet is sent. |
KeepAliveInterval | The retry interval, in milliseconds, to be used when a TCP keep-alive packet is sent and no response is received. |
Linger | When set to True, connections are terminated gracefully. |
LingerTime | Time in seconds to have the connection linger. |
LocalHost | The name of the local host through which connections are initiated or accepted. |
LocalPort | The TCP port in the local host where the component binds. |
MaxLineLength | The maximum amount of data to accumulate when no EOL is found. |
MaxTransferRate | The transfer rate limit in bytes per second. |
RecordLength | The length of received data records. |
TCPKeepAlive | Determines whether or not the keep alive socket option is enabled. |
UseIPv6 | Whether to use IPv6. |
TcpNoDelay | Whether or not to delay when sending packets. |
ReuseSSLSession | Determines if the SSL session is reused. |
SSLCipherStrength | The minimum cipher strength used for bulk encryption. |
SSLEnabledProtocols | Used to enable/disable the supported security protocols. |
SSLProvider | The name of the security provider to use. |
SSLSecurityFlags | Flags that control certificate verification. |
OpenSSLCADir | The path to a directory containing CA certificates. |
OpenSSLCAFile | Name of the file containing the list of CA's trusted by your application. |
OpenSSLCipherList | A string that controls the ciphers to be used by SSL. |
OpenSSLPrngSeedData | The data to seed the pseudo random number generator (PRNG). |
AbsoluteTimeout | Determines whether timeouts are inactivity timeouts or absolute timeouts. |
FirewallData | Used to send extra data to the firewall. |
InBufferSize | The size in bytes of the incoming queue of the socket. |
OutBufferSize | The size in bytes of the outgoing queue of the socket. |
CodePage | The system code page used for Unicode to Multibyte translations. |