CloudStorage Class
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
incloudstorage.cloudstorage()
Remarks
The CloudStorage class 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 class:
- Amazon S3
- Box.com
- Dropbox
- Google Drive
- Microsoft OneDrive
- SharePoint Online
The class 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 class 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 AccountAccessKey and AccountSecretKey. To authenticate with SharePoint Online set AccountURL, AccountUser, and AccountPassword.
Selecting a Provider
To specify the provider simply set ServiceProvider. This tells the class 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* properties.
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.
If LocalFile is set the file will be saved to the specified location. If 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 class 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 class 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.
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 class 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 class with short descriptions. Click on the links for further details.
AccountAccessKey | This property specifies the Amazon S3 Access Key. |
AccountPassword | This property specifies the SharePoint user's password. |
AccountSecretKey | This property specifies the Amazon S3 Secret Key. |
AccountURL | This property specifies the SharePoint site URL. |
AccountUser | This property specifies the SharePoint user. |
Authorization | OAuth 2.0 Authorization Token. |
DirListCount | The number of records in the DirList arrays. |
DirListFileName | This property holds the name of the file or folder. |
DirListFileSize | This property holds the size of the file in bytes. |
DirListFileTime | This property holds the modified date of the file. |
DirListIsDir | This property specifies whether the entry is a directory. |
EncryptionAlgorithm | The encryption algorithm. |
EncryptionPassword | The encryption password. |
FirewallAutoDetect | This property tells the component whether or not to automatically detect and use firewall system settings, if available. |
FirewallType | This property determines the type of firewall to connect through. |
FirewallHost | This property contains the name or IP address of firewall (optional). |
FirewallPassword | This property contains a password if authentication is to be used when connecting through the firewall. |
FirewallPort | This property contains the TCP port for the firewall Host . |
FirewallUser | This property contains a user name if authentication is to be used connecting through a firewall. |
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. |
ProxyAuthScheme | This property is used to tell the component which type of authorization to perform when connecting to the proxy. |
ProxyAutoDetect | This property tells the component whether or not to automatically detect and use proxy system settings, if available. |
ProxyPassword | This property contains a password if authentication is to be used for the proxy. |
ProxyPort | This property contains the TCP port for the proxy Server (default 80). |
ProxyServer | If a proxy Server is given, then the HTTP request is sent to the proxy instead of the server otherwise specified. |
ProxySSL | This property determines when to use SSL for the connection to the proxy. |
ProxyUser | This property contains a user name, if authentication is to be used for the proxy. |
RemoteFile | The name of the remote file. |
RemotePath | The current path on the server. |
ServiceProvider | The storage service provider. |
SSLAcceptServerCertEncoded | The certificate (PEM/base64 encoded). |
SSLCertEncoded | The certificate (PEM/base64 encoded). |
SSLCertStore | The name of the certificate store for the client certificate. |
SSLCertStorePassword | If the certificate store is of a type that requires a password, this property is used to specify that password in order to open the certificate store. |
SSLCertStoreType | The type of certificate store for this certificate. |
SSLCertSubject | The subject of the certificate used for client authentication. |
SSLServerCertEncoded | The certificate (PEM/base64 encoded). |
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 class 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 class 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 class 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. |