IPWorks Cloud 2020 C++ Edition

Questions / Feedback?

Download Method

Download the specified file.

Syntax

ANSI (Cross Platform)
int Download();

Unicode (Windows)
INT Download();
- (void)download;
#define MID_CLOUDSTORAGE_DOWNLOAD 4

IPWORKSCLOUD_EXTERNAL int IPWORKSCLOUD_CALL IPWorksCloud_CloudStorage_Do(void *lpObj, int methid, int cparam, void *param[], int cbparam[], int64 *lpllVal);

Remarks

This method downloads the specified 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 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 downloaded 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();

Error Handling (C++)

This method returns a result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. If an error occurs, the GetLastError() method can be called to retrieve the associated error message. (Note: This method's result code can also be obtained by calling the GetLastErrorCode() method after it returns.)

Copyright (c) 2022 /n software inc. - All rights reserved.
IPWorks Cloud 2020 C++ Edition - Version 20.0 [Build 8265]