### Retrieve download progression with DownloadFileAsync and IProgress Source: https://gpailler.github.io/MegaApiClient/articles/faq.html Use async methods like DownloadAsync / UploadAsync to retrieve progression. This example logs in anonymously, gets a node from a file link, and downloads the file with a progress handler that prints the percentage. ```csharp async void Main() { var client = new MegaApiClient(); client.LoginAnonymous(); Uri fileLink = new Uri("https://mega.nz/#!bkwkHC7D!AWJuto8_fhleAI2WG0RvACtKkL_s9tAtvBXXDUp2bQk"); INode node = client.GetNodeFromLink(fileLink); IProgress progressHandler = new Progress(x => Console.WriteLine("{0}%", x)); await client.DownloadFileAsync(fileLink, node.Name, progressHandler); client.Logout(); } ``` -------------------------------- ### Options.ApplicationKey Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.Options.html Gets the application key used by the client. ```APIDOC ## Property: ApplicationKey ### Description Gets the application key. ### Property Declaration public string ApplicationKey { get; } ### Property Value Type: System.String ``` -------------------------------- ### Download file to a specific location with Download method Source: https://gpailler.github.io/MegaApiClient/articles/faq.html Use a stream with the Download method to control the destination of your download. The example writes the downloaded stream to a new file in a subfolder. ```csharp var destination = @"SubFolder\MyFile.jpg"; using (var stream = client.Download(node)) { using (var fileStream = new FileStream(destination, FileMode.CreateNew)) { stream.CopyTo(fileStream); } } ``` -------------------------------- ### Retrieve upload/download progression with custom ProgressionStream Source: https://gpailler.github.io/MegaApiClient/articles/faq.html Use the Download / Upload methods with a custom stream implementation to retrieve progression. The example shows uploading and downloading with a ProgressionStream that reports progress, and includes the full ProgressionStream class definition. ```csharp // Upload using (var fileStream = new FileStream(filepath, FileMode.Open)) using (var progressionStream = new ProgressionStream(fileStream, x => Console.WriteLine("{0}%", x))) { client.Upload(progressionStream, filename, parent); } // Download using (var downloadStream = client.Download(node)) using (var progressionStream = new ProgressionStream(downloadStream, x => Console.WriteLine("{0}%", x))) using (var fileStream = new FileStream(filePath, FileMode.Create)) { progressionStream.CopyTo(fileStream); } public class ProgressionStream : Stream { public delegate void ProgressionHandler(double progression); private Stream _sourceStream; private ProgressionHandler _progressionHandler; public ProgressionStream(Stream sourceStream, ProgressionHandler progressionHandler) { this._sourceStream = sourceStream; this._progressionHandler = progressionHandler; } public override int Read(byte[] array, int offset, int count) { this._progressionHandler(this.Position / (double)this.Length * 100); return this._sourceStream.Read(array, offset, count); } public override bool CanRead { get { return this._sourceStream.CanRead; } } public override bool CanSeek { get { return this._sourceStream.CanSeek; } } public override bool CanWrite { get { return this._sourceStream.CanWrite; } } public override long Length { get { return this._sourceStream.Length; } } public override long Position { get { return this._sourceStream.Position; } set { this._sourceStream.Position = value; } } public override void Flush() { this._sourceStream.Flush(); } public override long Seek(long offset, SeekOrigin origin) { return this._sourceStream.Seek(offset, origin); } public override void SetLength(long value) { this._sourceStream.SetLength(value); } public override void Write(byte[] buffer, int offset, int count) { this._sourceStream.Write(buffer, offset, count); } } ``` -------------------------------- ### Salt Property Declaration Source: https://gpailler.github.io/MegaApiClient/api/Medo.Security.Cryptography.Pbkdf2.html Gets the salt bytes. ```csharp public byte[] Salt { get; } ``` -------------------------------- ### IAccountInformation.Metrics Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.IAccountInformation.html Gets the collection of storage metrics for the account. ```APIDOC ## IAccountInformation.Metrics ### Description Gets the collection of storage metrics for the account. ### Property `IEnumerable Metrics { get; }` ### Property Value - **Type**: `System.Collections.Generic.IEnumerable` - **Description**: The collection of storage metrics. ``` -------------------------------- ### Options.BufferSize Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.Options.html Gets the size of the buffer used when downloading files, which affects progression and CPU usage. ```APIDOC ## Property: BufferSize ### Description Size of the buffer used when downloading files. A lower value means more progression reports but a possible higher CPU usage. ### Declaration public int BufferSize { get; } ### Property Value Type: System.Int32 ``` -------------------------------- ### Set proxy credentials for the whole application Source: https://gpailler.github.io/MegaApiClient/articles/faq.html Add this line to specify proxy credentials for the whole application when using a proxy with authentication. Note the typo 'NetworkCredentails' in the original example. ```csharp WebRequest.DefaultWebProxy.Credentials = New NetworkCredentails("Username", "Password") ``` -------------------------------- ### Algorithm Property Source: https://gpailler.github.io/MegaApiClient/api/Medo.Security.Cryptography.Pbkdf2.html Gets the HMAC algorithm used for generating the key. ```APIDOC ## Algorithm Property ### Description Gets the HMAC algorithm used for generating the key. ### Declaration ```csharp public HMAC Algorithm { get; } ``` ### Property Value - **Type**: System.Security.Cryptography.HMAC ``` -------------------------------- ### MasterKey Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.MegaApiClient.LogonSessionToken.html Gets the master key associated with the logon session token. ```APIDOC ## MasterKey ### Description Gets the master key associated with the logon session token. ### Declaration public byte[] MasterKey { get; } ### Property Value - **Type**: System.Byte[] ``` -------------------------------- ### Algorithm Property Declaration Source: https://gpailler.github.io/MegaApiClient/api/Medo.Security.Cryptography.Pbkdf2.html Gets the HMAC algorithm used for generating the key. ```csharp public HMAC Algorithm { get; } ``` -------------------------------- ### WebClient.BufferSize Property Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.WebClient.html Gets or sets the buffer size used for data transfer operations. ```APIDOC ## WebClient.BufferSize Property ### Description Gets or sets the buffer size used for data transfer operations. ### Property Value - **System.Int32** - The buffer size in bytes. ``` -------------------------------- ### Upload a file and retrieve public download link with CreateFolder() and UploadFile() Source: https://gpailler.github.io/MegaApiClient/articles/samples.html Logs in with credentials, creates a folder named "Upload" under the root node, uploads "MyFile.ext" into it, and prints the public download link obtained via GetDownloadLink(). ```csharp using CG.Web.MegaApiClient; void Main() { MegaApiClient client = new MegaApiClient(); client.Login("username@domain.com", "passw0rd"); IEnumerable nodes = client.GetNodes(); INode root = nodes.Single(x => x.Type == NodeType.Root); INode myFolder = client.CreateFolder("Upload", root); INode myFile = client.UploadFile("MyFile.ext", myFolder); Uri downloadLink = client.GetDownloadLink(myFile); Console.WriteLine(downloadLink); client.Logout(); } ``` -------------------------------- ### Initialize Pbkdf2 with SHA-256 HMAC Source: https://gpailler.github.io/MegaApiClient/api/Medo.Security.Cryptography.Pbkdf2.html Shows how to create a Pbkdf2 instance using HMACSHA256, a password string, and a salt string, then retrieve derived bytes. ```csharp using (var hmac = new HMACSHA256()) { var df = new Pbkdf2(hmac, "password", "salt"); var bytes = df.GetBytes(); } ``` -------------------------------- ### IAccountInformation.UsedQuota Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.IAccountInformation.html Gets the used quota of the account. ```APIDOC ## IAccountInformation.UsedQuota ### Description Gets the used quota of the account. ### Property `long UsedQuota { get; }` ### Property Value - **Type**: `System.Int64` - **Description**: The used quota. ``` -------------------------------- ### Options(String, Boolean, Options.ComputeApiRequestRetryWaitDelayDelegate, Int32, Int32, Int64) Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.Options.html Initializes a new instance of the Options class with specified configuration parameters. Use this constructor to customize the client behavior, such as API key, synchronization, buffer sizes, and retry delay logic. ```APIDOC ## [Constructor] Options(String, Boolean, Options.ComputeApiRequestRetryWaitDelayDelegate, Int32, Int32, Int64) ### Description Creates a new Options instance with configurable parameters for the MegaApiClient. Customize application key, request synchronization, retry delay, buffer size, chunk pack size, and progress reporting chunk size. ### Constructor Options(String, Boolean, Options.ComputeApiRequestRetryWaitDelayDelegate, Int32, Int32, Int64) ### Parameters - **applicationKey** (System.String) - Optional - The application key to use. - **synchronizeApiRequests** (System.Boolean) - Optional - Indicates whether API requests should be synchronized. - **computeApiRequestRetryWaitDelay** (Options.ComputeApiRequestRetryWaitDelayDelegate) - Optional - Delegate to compute retry wait delay. - **bufferSize** (System.Int32) - Optional - Size of the buffer used when downloading files. - **chunksPackSize** (System.Int32) - Optional - Size of the chunk pack used for uploads. - **reportProgressChunkSize** (System.Int64) - Optional - Size of the chunk for progress reporting. ### Response This is a constructor and does not return a value. ``` -------------------------------- ### IAccountInformation.TotalQuota Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.IAccountInformation.html Gets the total quota of the account. ```APIDOC ## IAccountInformation.TotalQuota ### Description Gets the total quota of the account. ### Property `long TotalQuota { get; }` ### Property Value - **Type**: `System.Int64` - **Description**: The total quota. ``` -------------------------------- ### IterationCount Property Declaration Source: https://gpailler.github.io/MegaApiClient/api/Medo.Security.Cryptography.Pbkdf2.html Gets the iteration count. ```csharp public int IterationCount { get; } ``` -------------------------------- ### List all files and folders recursively with GetNodes() Source: https://gpailler.github.io/MegaApiClient/articles/samples.html Logs in with credentials, calls GetNodes() to retrieve all metadata (which can be time consuming), then recursively prints each child's name, size, and creation date, indenting directories by level. Ends with Logout(). ```csharp using CG.Web.MegaApiClient; void Main() { MegaApiClient client = new MegaApiClient(); client.Login("username@domain.com", "passw0rd"); // GetNodes retrieves all files/folders metadata from Mega // so this method can be time consuming IEnumerable nodes = client.GetNodes(); INode parent = nodes.Single(n => n.Type == NodeType.Root); DisplayNodesRecursive(nodes, parent); client.Logout(); } void DisplayNodesRecursive(IEnumerable nodes, INode parent, int level = 0) { IEnumerable children = nodes.Where(x => x.ParentId == parent.Id); foreach (INode child in children) { string infos = $"- {child.Name} - {child.Size} bytes - {child.CreationDate}"; Console.WriteLine(infos.PadLeft(infos.Length + level, '\t')); if (child.Type == NodeType.Directory) { DisplayNodesRecursive(nodes, child, level + 1); } } } ``` -------------------------------- ### Options.DefaultApplicationKey Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.Options.html Constant field specifying the default application key ('axhQiYyQ'). ```APIDOC ## Field: DefaultApplicationKey ### Description Default application key used by the client. ### Declaration public const string DefaultApplicationKey = "axhQiYyQ" ### Field Value Type: System.String Value: "axhQiYyQ" ``` -------------------------------- ### CreateFolder(String, INode) Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.MegaApiClient.html Creates a folder on the filesystem. ```APIDOC ## CreateFolder(String, INode) ### Description Creates a folder on the filesystem. ### Method public INode CreateFolder(string name, INode parent) ### Parameters - **name** (System.String) - Required - Folder name. - **parent** (INode) - Required - Parent node to attach created folder. ### Returns INode - The created folder node. ### Exceptions - System.NotSupportedException - Not logged in. - ApiException - Mega.co.nz service reports an error. - System.ArgumentNullException - name or parent is null. - System.ArgumentException - parent is not valid (all types are allowed except File). ``` -------------------------------- ### ApiUrl Property Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.ApiRequestFailedEventArgs.html Gets the URL of the failed request. ```APIDOC ## Property: ApiUrl ### Description Gets the URL of the failed request. ### Declaration public Uri ApiUrl { get; } ### Property Value - **System.Uri** - The URL of the failed request. ``` -------------------------------- ### Pbkdf2 Constructor with HMAC, string password, string salt, int iterations Source: https://gpailler.github.io/MegaApiClient/api/Medo.Security.Cryptography.Pbkdf2.html Declares the constructor that takes string password, salt, and iteration count. Throws ArgumentNullException if any parameter is null. ```csharp public Pbkdf2(HMAC algorithm, string password, string salt, int iterations) ``` -------------------------------- ### Pbkdf2 Constructor with HMAC, byte[] password, byte[] salt Source: https://gpailler.github.io/MegaApiClient/api/Medo.Security.Cryptography.Pbkdf2.html Declares the constructor that takes an HMAC algorithm, a byte array password, and a byte array salt. Throws ArgumentNullException if any parameter is null. ```csharp public Pbkdf2(HMAC algorithm, byte[] password, byte[] salt) ``` -------------------------------- ### IsLoggedIn Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.MegaApiClient.html Gets a value indicating whether the client is logged in. ```APIDOC ## IsLoggedIn ### Description Gets a value indicating whether the client is logged in. ### Property public bool IsLoggedIn { get; } ### Returns System.Boolean - True if logged in, otherwise false. ``` -------------------------------- ### SessionId Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.MegaApiClient.LogonSessionToken.html Gets the session identifier for the logon session token. ```APIDOC ## SessionId ### Description Gets the session identifier for the logon session token. ### Declaration public string SessionId { get; } ### Property Value - **Type**: System.String ``` -------------------------------- ### Pbkdf2 Constructor with HMAC, string password, string salt Source: https://gpailler.github.io/MegaApiClient/api/Medo.Security.Cryptography.Pbkdf2.html Declares the constructor that takes string password and salt. Throws ArgumentNullException if any parameter is null. ```csharp public Pbkdf2(HMAC algorithm, string password, string salt) ``` -------------------------------- ### Options.ReportProgressChunkSize Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.Options.html Gets the chunk size used for reporting progress. ```APIDOC ## Property: ReportProgressChunkSize ### Description Gets the chunk size used for progress reporting. ### Declaration public long ReportProgressChunkSize { get; } ### Property Value Type: System.Int64 ``` -------------------------------- ### LoginAsync(String, String, String) Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.MegaApiClient.html Asynchronously logs in to Mega.co.nz using email, password, and optional MFA key. ```APIDOC ## LoginAsync(String, String, String) ### Description Asynchronously logs in to Mega.co.nz service. ### Method LoginAsync ### Declaration public Task LoginAsync(string email, string password, string mfaKey = null) ### Parameters - **email** (System.String) - Required - Email address for login. - **password** (System.String) - Required - Password for login. - **mfaKey** (System.String) - Optional - Multi-factor authentication key. ### Returns - **Task** - A task representing the asynchronous operation, containing the logon session token. ``` -------------------------------- ### RetryDelay Property Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.ApiRequestFailedEventArgs.html Gets the retry delay before the next attempt. ```APIDOC ## Property: RetryDelay ### Description Gets the retry delay before the next attempt. ### Declaration public TimeSpan RetryDelay { get; } ### Property Value - **System.TimeSpan** - The retry delay. ``` -------------------------------- ### AuthInfos Constructor Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.MegaApiClient.AuthInfos.html Initializes a new instance of the AuthInfos class with the specified email, hash, password AES key, and optional MFA key. ```APIDOC ## [Constructor] AuthInfos(String, String, Byte[], String) ### Description Initializes a new instance of the AuthInfos class with the provided authentication data. ### Syntax ```csharp public AuthInfos(string email, string hash, byte[] passwordAesKey, string mfaKey = null) ``` ### Parameters - **email** (System.String) - The email address for authentication. - **hash** (System.String) - The authentication hash. - **passwordAesKey** (System.Byte[]) - The AES key derived from the password. - **mfaKey** (System.String) - Optional multi-factor authentication key. Default is null. ### Return Value No return value (constructor). ``` -------------------------------- ### ResponseJson Property Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.ApiRequestFailedEventArgs.html Gets the JSON response from the failed request. ```APIDOC ## Property: ResponseJson ### Description Gets the JSON response from the failed request. ### Declaration public string ResponseJson { get; } ### Property Value - **System.String** - The JSON response. ``` -------------------------------- ### Exception Property Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.ApiRequestFailedEventArgs.html Gets the exception that occurred during the failed request. ```APIDOC ## Property: Exception ### Description Gets the exception that occurred during the failed request. ### Declaration public Exception Exception { get; } ### Property Value - **System.Exception** - The exception. ``` -------------------------------- ### WebClient Constructor Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.WebClient.html Initializes a new instance of the WebClient class with optional response timeout and user agent. ```APIDOC ## WebClient(int responseTimeout = -1, ProductInfoHeaderValue userAgent = null) ### Description Initializes a new instance of the WebClient class. ### Parameters - **responseTimeout** (System.Int32) - Optional - Response timeout in milliseconds. Default is -1. - **userAgent** (System.Net.Http.Headers.ProductInfoHeaderValue) - Optional - User agent header value. ### Example ```csharp var client = new WebClient(); ``` ``` -------------------------------- ### AttemptNum Property Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.ApiRequestFailedEventArgs.html Gets the attempt number of the failed request. ```APIDOC ## Property: AttemptNum ### Description Gets the attempt number of the failed request. ### Declaration public int AttemptNum { get; } ### Property Value - **System.Int32** - The attempt number. ``` -------------------------------- ### Login(String, String, String) Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.IMegaApiClient.html Performs a login using an email, password, and multi-factor authentication key. ```APIDOC ## Login(String, String, String) ### Description Performs a login using an email, password, and multi-factor authentication key. ### Method Login ### Parameters - **email** (System.String) - The email address. - **password** (System.String) - The password. - **mfaKey** (System.String) - The multi-factor authentication key. ### Returns - **MegaApiClient.LogonSessionToken** - The logon session token. ``` -------------------------------- ### Salt Property Source: https://gpailler.github.io/MegaApiClient/api/Medo.Security.Cryptography.Pbkdf2.html Gets the salt bytes used in the PBKDF2 operation. ```APIDOC ## Salt Property ### Description Gets the salt bytes used in the PBKDF2 operation. ### Declaration ```csharp public byte[] Salt { get; } ``` ### Property Value - **Type**: System.Byte[] ``` -------------------------------- ### IterationCount Property Source: https://gpailler.github.io/MegaApiClient/api/Medo.Security.Cryptography.Pbkdf2.html Gets the iteration count used in the PBKDF2 operation. ```APIDOC ## IterationCount Property ### Description Gets the iteration count used in the PBKDF2 operation. ### Declaration ```csharp public int IterationCount { get; } ``` ### Property Value - **Type**: System.Int32 ``` -------------------------------- ### Pbkdf2(HMAC, String, String) Source: https://gpailler.github.io/MegaApiClient/api/Medo.Security.Cryptography.Pbkdf2.html Creates a new instance of Pbkdf2 using an HMAC algorithm, string password, and string salt. ```APIDOC ## Pbkdf2(HMAC, String, String) ### Description Creates a new instance of the Pbkdf2 class with the specified HMAC algorithm, password, and salt as strings. ### Constructor ```csharp public Pbkdf2(HMAC algorithm, string password, string salt) ``` ### Parameters - **algorithm** (System.Security.Cryptography.HMAC) - Required - HMAC algorithm to use. - **password** (System.String) - Required - The password used to derive the key. - **salt** (System.String) - Required - The key salt used to derive the key. ### Exceptions - **System.ArgumentNullException** - Algorithm cannot be null - Password cannot be null. -or- Salt cannot be null. ``` -------------------------------- ### Login() Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.IMegaApiClient.html Performs a login using the default authentication method. ```APIDOC ## Login() ### Description Performs a login using the default authentication method. ### Method Login ### Returns - **void** - No return value. ``` -------------------------------- ### CreateFolderAsync(String, INode) Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.MegaApiClient.html Asynchronously creates a folder on the filesystem. ```APIDOC ## CreateFolderAsync(String, INode) ### Description Asynchronously creates a folder on the filesystem. ### Method public Task CreateFolderAsync(string name, INode parent) ### Parameters - **name** (System.String) - Required - Folder name. - **parent** (INode) - Required - Parent node to attach created folder. ### Returns System.Threading.Tasks.Task - A task representing the asynchronous operation, with the created folder node as result. ``` -------------------------------- ### Options.SynchronizeApiRequests Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.Options.html Gets a value indicating whether API requests are synchronized. ```APIDOC ## Property: SynchronizeApiRequests ### Description Gets whether API requests are synchronized. ### Declaration public bool SynchronizeApiRequests { get; } ### Property Value Type: System.Boolean ``` -------------------------------- ### Pbkdf2(HMAC, String, String, Int32) Source: https://gpailler.github.io/MegaApiClient/api/Medo.Security.Cryptography.Pbkdf2.html Creates a new instance of Pbkdf2 with an HMAC algorithm, string password, string salt, and iteration count. ```APIDOC ## Pbkdf2(HMAC, String, String, Int32) ### Description Creates a new instance of the Pbkdf2 class with the specified HMAC algorithm, password, salt, and iteration count. ### Constructor ```csharp public Pbkdf2(HMAC algorithm, string password, string salt, int iterations) ``` ### Parameters - **algorithm** (System.Security.Cryptography.HMAC) - Required - HMAC algorithm to use. - **password** (System.String) - Required - The password used to derive the key. - **salt** (System.String) - Required - The key salt used to derive the key. - **iterations** (System.Int32) - Required - The number of iterations for the operation. ### Exceptions - **System.ArgumentNullException** - Algorithm cannot be null - Password cannot be null. -or- Salt cannot be null. ``` -------------------------------- ### Pbkdf2 Constructor with HMAC, byte[] password, byte[] salt, int iterations Source: https://gpailler.github.io/MegaApiClient/api/Medo.Security.Cryptography.Pbkdf2.html Declares the constructor that includes an iteration count. Throws ArgumentNullException if any parameter is null. ```csharp public Pbkdf2(HMAC algorithm, byte[] password, byte[] salt, int iterations) ``` -------------------------------- ### ApiException.Message Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.ApiException.html Gets the error message for the exception. This property overrides System.Exception.Message. ```APIDOC ## Property: Message ### Description Gets the error message for the exception. ### Declaration public override string Message { get; } ### Property Value - **Type**: System.String - **Description**: The error message. ### Overrides System.Exception.Message ``` -------------------------------- ### Hash Property Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.MegaApiClient.AuthInfos.html Gets the authentication hash associated with the authentication information. ```APIDOC ## [Property] Hash ### Description Gets the authentication hash associated with the authentication information. ### Declaration ```csharp public string Hash { get; } ``` ### Property Value **Type:** System.String - The authentication hash. ### Remarks This property is read-only. ``` -------------------------------- ### LoginAsync(String, String, String) Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.IMegaApiClient.html Asynchronously logs in with email, password, and an optional multi-factor authentication key. Returns a logon session token. ```APIDOC ## LoginAsync(String, String, String) ### Description Asynchronously logs in using email and password, with optional mfaKey for two-factor authentication. ### Declaration ```csharp Task LoginAsync(string email, string password, string mfaKey = null) ``` ### Parameters - **email** (System.String) - The email address. - **password** (System.String) - The password. - **mfaKey** (System.String) - Optional multi-factor authentication key. ### Returns - **Task** - Returns the logon session token. ``` -------------------------------- ### Email Property Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.MegaApiClient.AuthInfos.html Gets the email address associated with the authentication information. ```APIDOC ## [Property] Email ### Description Gets the email address associated with the authentication information. ### Declaration ```csharp public string Email { get; } ``` ### Property Value - **Type**: System.String - The email address. ### Remarks This property is read-only. ``` -------------------------------- ### Login(String, String) Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.IMegaApiClient.html Performs a login using an email and password. ```APIDOC ## Login(String, String) ### Description Performs a login using an email and password. ### Method Login ### Parameters - **email** (System.String) - The email address. - **password** (System.String) - The password. ### Returns - **MegaApiClient.LogonSessionToken** - The logon session token. ``` -------------------------------- ### MegaApiClient(Options) Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.MegaApiClient.html Instantiates a new MegaApiClient object with custom Options and default IWebClient. ```APIDOC ## MegaApiClient(Options) ### Description Instantiates a new MegaApiClient object with custom Options and default IWebClient. ### Method Constructor ### Signature public MegaApiClient(Options options) ### Parameters - **options** (Options) - Required - The custom options to use. ### Returns MegaApiClient instance ``` -------------------------------- ### Options.ComputeApiRequestRetryWaitDelay Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.Options.html Gets the delegate that computes the retry wait delay for API requests. ```APIDOC ## Property: ComputeApiRequestRetryWaitDelay ### Description Gets the delegate used to compute API request retry wait delay. ### Declaration public Options.ComputeApiRequestRetryWaitDelayDelegate ComputeApiRequestRetryWaitDelay { get; } ### Property Value Type: Options.ComputeApiRequestRetryWaitDelayDelegate ``` -------------------------------- ### DownloadFile(Uri, String, Nullable) Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.MegaApiClient.html Downloads a specified Uri from Mega and saves it to the specified file. ```APIDOC ## DownloadFile(Uri, String, Nullable) ### Description Download a specified Uri from Mega and save it to the specified file. ### Declaration public void DownloadFile(Uri uri, string outputFile, CancellationToken? cancellationToken = null) ### Parameters - **uri** (System.Uri) - Required - Uri to download - **outputFile** (System.String) - Required - File to save the Uri to - **cancellationToken** (System.Nullable) - Optional - CancellationToken used to cancel the action ### Exceptions - **System.NotSupportedException** - Not logged in - **ApiException** - Mega.co.nz service reports an error - **System.ArgumentNullException** - uri or outputFile is null - **System.ArgumentException** - Uri is not valid (id and key are required) - **DownloadException** - Checksum is invalid. Downloaded data are corrupted ``` -------------------------------- ### MegaApiClient(Options, IWebClient) Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.MegaApiClient.html Instantiates a new MegaApiClient object with custom Options and custom IWebClient. ```APIDOC ## MegaApiClient(Options, IWebClient) ### Description Instantiates a new MegaApiClient object with custom Options and custom IWebClient. ### Method Constructor ### Signature public MegaApiClient(Options options, IWebClient webClient) ### Parameters - **options** (Options) - Required - The custom options to use. - **webClient** (IWebClient) - Required - The custom web client to use. ### Returns MegaApiClient instance ``` -------------------------------- ### ApiResult Property Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.ApiRequestFailedEventArgs.html Gets the API result code associated with the failed request. ```APIDOC ## Property: ApiResult ### Description Gets the API result code associated with the failed request. ### Declaration public ApiResultCode ApiResult { get; } ### Property Value - **ApiResultCode** - The API result code. ``` -------------------------------- ### MFAKey Property Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.MegaApiClient.AuthInfos.html Gets the multi-factor authentication key associated with the authentication information. ```APIDOC ## [Property] MFAKey ### Description Gets the multi-factor authentication key associated with the authentication information. ### Declaration ```csharp public string MFAKey { get; } ``` ### Property Value **Type:** System.String - The multi-factor authentication key. ### Remarks This property is read-only. ``` -------------------------------- ### Pbkdf2(HMAC, Byte[], Byte[]) Source: https://gpailler.github.io/MegaApiClient/api/Medo.Security.Cryptography.Pbkdf2.html Creates a new instance of Pbkdf2 using an HMAC algorithm, a byte array password, and a byte array salt. ```APIDOC ## Pbkdf2(HMAC, Byte[], Byte[]) ### Description Creates a new instance of the Pbkdf2 class with the specified HMAC algorithm, password, and salt. ### Constructor ```csharp public Pbkdf2(HMAC algorithm, byte[] password, byte[] salt) ``` ### Parameters - **algorithm** (System.Security.Cryptography.HMAC) - Required - HMAC algorithm to use. - **password** (System.Byte[]) - Required - The password used to derive the key. - **salt** (System.Byte[]) - Required - The key salt used to derive the key. ### Exceptions - **System.ArgumentNullException** - Algorithm cannot be null - Password cannot be null. -or- Salt cannot be null. ``` -------------------------------- ### MegaApiClient() Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.MegaApiClient.html Instantiates a new MegaApiClient object with default Options and default IWebClient. ```APIDOC ## MegaApiClient() ### Description Instantiates a new MegaApiClient object with default Options and default IWebClient. ### Method Constructor ### Signature public MegaApiClient() ### Parameters None ### Returns MegaApiClient instance ``` -------------------------------- ### PasswordAesKey Property Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.MegaApiClient.AuthInfos.html Gets the AES key derived from the password, used for cryptographic operations. ```APIDOC ## [Property] PasswordAesKey ### Description Gets the AES key derived from the password, used for cryptographic operations. ### Declaration ```csharp public byte[] PasswordAesKey { get; } ``` ### Property Value **Type:** System.Byte[] - The AES key bytes. ### Remarks This property is read-only. ``` -------------------------------- ### LoginAsync() Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.IMegaApiClient.html Asynchronously performs a login using the default authentication method. ```APIDOC ## LoginAsync() ### Description Asynchronously performs a login using the default authentication method. ### Method LoginAsync ### Returns - **Task** - A task representing the asynchronous operation. ``` -------------------------------- ### DownloadFileAsync(Uri, String, IProgress, Nullable) Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.MegaApiClient.html Asynchronously downloads a file from a given URI to a local output file, with optional progress reporting and cancellation support. ```APIDOC ## DownloadFileAsync(Uri, String, IProgress, Nullable) ### Description Asynchronously downloads a file from the specified URI to the specified output file path. ### Method DownloadFileAsync ### Signature public Task DownloadFileAsync(Uri uri, string outputFile, IProgress progress = null, CancellationToken? cancellationToken = null) ### Parameters - **uri** (System.Uri) - Required - The URI of the file to download. - **outputFile** (System.String) - Required - The local file path where the file will be saved. - **progress** (System.IProgress) - Optional - Progress reporter for download progress. - **cancellationToken** (System.Nullable) - Optional - Cancellation token to cancel the operation. ### Returns - **Task** - A task representing the asynchronous operation. ``` -------------------------------- ### WebClient.GetRequestRaw(Uri) Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.WebClient.html Performs a raw GET request to the specified URL and returns the response stream. ```APIDOC ## WebClient.GetRequestRaw(Uri url) ### Description Performs a raw GET request to the specified URL and returns the response stream. ### Parameters - **url** (System.Uri) - Required - The URL to send the GET request to. ### Returns - **System.IO.Stream** - The response stream. ### Example ```csharp Stream stream = client.GetRequestRaw(new Uri("https://example.com/file")); ``` ``` -------------------------------- ### Login(String, String) Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.MegaApiClient.html Logs in to the Mega.co.nz service using email and password credentials. ```APIDOC ## Login(String, String) ### Description Logs in to the Mega.co.nz service using email and password credentials. ### Method Login ### Signature public MegaApiClient.LogonSessionToken Login(string email, string password) ### Parameters - **email** (System.String) - The email address. - **password** (System.String) - The password. ### Returns - **MegaApiClient.LogonSessionToken** - The logon session token. ### Exceptions - **ApiException** - Thrown when service is not available or credentials are invalid. - **System.ArgumentNullException** - Thrown when email or password is null. - **System.NotSupportedException** - Thrown when already logged in. ``` -------------------------------- ### ApiException.ApiResultCode Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.ApiException.html Gets the API result code associated with the exception. This property is read-only and returns an ApiResultCode value. ```APIDOC ## Property: ApiResultCode ### Description Gets the API result code associated with the exception. ### Declaration public ApiResultCode ApiResultCode { get; } ### Property Value - **Type**: ApiResultCode - **Description**: The API result code. ### Remarks This property is read-only. ``` -------------------------------- ### LoginAsync(MegaApiClient.AuthInfos) Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.MegaApiClient.html Asynchronously logs in using hashed credentials. ```APIDOC ## LoginAsync(MegaApiClient.AuthInfos) ### Description Asynchronously logs in using hashed credentials. ### Method LoginAsync ### Signature public Task LoginAsync(MegaApiClient.AuthInfos authInfos) ### Parameters - **authInfos** (MegaApiClient.AuthInfos) - Authentication informations. ### Returns - **Task** - A task representing the asynchronous operation, with the logon session token as the result. ``` -------------------------------- ### Options.ChunksPackSize Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.Options.html Gets the maximum size of a fragment chunk pack used during uploads. The special value -1 merges all chunks into a single fragment and a single upload. ```APIDOC ## Property: ChunksPackSize ### Description Gets the chunk pack size used during uploads. Upload is splitted in multiple fragments and the upload method tries to upload multiple fragments at once until the total size reaches this value. The value -1 merges all chunks in a single fragment. ### Declaration public int ChunksPackSize { get; } ### Property Value Type: System.Int32 ``` -------------------------------- ### Download a file from a Mega link with GetNodeFromLink() Source: https://gpailler.github.io/MegaApiClient/articles/samples.html Uses LoginAnonymous() to download a single file from a public Mega link. Calls GetNodeFromLink() to obtain the node, prints its name, then DownloadFile() saves it locally with that name. ```csharp using CG.Web.MegaApiClient; void Main() { MegaApiClient client = new MegaApiClient(); client.LoginAnonymous(); Uri fileLink = new Uri("https://mega.nz/file/W0UAgJaK#XOYyTETrIy8daz3_dw3fdh6Hh8EFEdrnbyoop1r9R6g"); INode node = client.GetNodeFromLink(fileLink); Console.WriteLine($"Downloading {node.Name}"); client.DownloadFile(fileLink, node.Name); client.Logout(); } ``` -------------------------------- ### Enforce TLS 1.2 for .NET Framework 4 Source: https://gpailler.github.io/MegaApiClient/index.html Use this cast to enforce TLS 1.2 on .NET Framework 4, provided .NET 4.5 is installed on the machine. ```csharp ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; ``` -------------------------------- ### Login(String, String, String) Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.MegaApiClient.html Logs in to the Mega.co.nz service using email, password, and MFA key. ```APIDOC ## Login(String, String, String) ### Description Logs in to the Mega.co.nz service using email, password, and MFA key. ### Method Login ### Signature public MegaApiClient.LogonSessionToken Login(string email, string password, string mfaKey) ### Parameters - **email** (System.String) - The email address. - **password** (System.String) - The password. - **mfaKey** (System.String) - The MFA key. ### Returns - **MegaApiClient.LogonSessionToken** - The logon session token. ### Exceptions - **ApiException** - Thrown when service is not available or credentials are invalid. - **System.ArgumentNullException** - Thrown when email or password is null. - **System.NotSupportedException** - Thrown when already logged in. ``` -------------------------------- ### LogonSessionToken(String, Byte[]) Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.MegaApiClient.LogonSessionToken.html Constructor for creating a LogonSessionToken instance with a session ID and master key. ```APIDOC ## LogonSessionToken(String, Byte[]) ### Description Initializes a new instance of the LogonSessionToken class with the specified session ID and master key. ### Declaration public LogonSessionToken(string sessionId, byte[] masterKey) ### Parameters - **sessionId** (System.String) - The session identifier. - **masterKey** (System.Byte[]) - The master key associated with the session. ``` -------------------------------- ### LoginAsync() Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.MegaApiClient.html Asynchronously logs in anonymously to the Mega.co.nz service. ```APIDOC ## LoginAsync() ### Description Asynchronously logs in anonymously to the Mega.co.nz service. ### Method LoginAsync ### Signature public Task LoginAsync() ### Returns - **Task** - A task representing the asynchronous operation. ``` -------------------------------- ### DownloadAsync(Uri, IProgress, Nullable) Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.MegaApiClient.html Asynchronously downloads a URI to a stream with progress reporting. ```APIDOC ## DownloadAsync(Uri, IProgress, Nullable) ### Description Asynchronously downloads a URI to a stream. ### Declaration public Task DownloadAsync(Uri uri, IProgress progress = null, CancellationToken? cancellationToken = null) ### Parameters - **uri** (System.Uri) - Required - The URI to download - **progress** (System.IProgress) - Optional - Progress reporter - **cancellationToken** (System.Nullable) - Optional - Cancellation token ### Returns - **System.Threading.Tasks.Task** - A task representing the asynchronous operation, with a result of the downloaded stream ``` -------------------------------- ### GenerateAuthInfosAsync(String, String, String) Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.IMegaApiClient.html Asynchronously generates authentication information for a given email, password, and MFA key. ```APIDOC ## GenerateAuthInfosAsync(String, String, String) ### Description Asynchronously generates authentication information for a given email, password, and MFA key. ### Method GenerateAuthInfosAsync ### Parameters - **email** (System.String) - Required - The user's email address. - **password** (System.String) - Required - The user's password. - **mfaKey** (System.String) - Required - The multi-factor authentication key. ### Returns - **Task** (System.Threading.Tasks.Task) - A task representing the asynchronous operation, with the generated authentication information. ``` -------------------------------- ### Pbkdf2(HMAC, Byte[], Byte[], Int32) Source: https://gpailler.github.io/MegaApiClient/api/Medo.Security.Cryptography.Pbkdf2.html Creates a new instance of Pbkdf2 with an HMAC algorithm, byte array password, byte array salt, and iteration count. ```APIDOC ## Pbkdf2(HMAC, Byte[], Byte[], Int32) ### Description Creates a new instance of the Pbkdf2 class with the specified HMAC algorithm, password, salt, and iteration count. ### Constructor ```csharp public Pbkdf2(HMAC algorithm, byte[] password, byte[] salt, int iterations) ``` ### Parameters - **algorithm** (System.Security.Cryptography.HMAC) - Required - HMAC algorithm to use. - **password** (System.Byte[]) - Required - The password used to derive the key. - **salt** (System.Byte[]) - Required - The key salt used to derive the key. - **iterations** (System.Int32) - Required - The number of iterations for the operation. ### Exceptions - **System.ArgumentNullException** - Algorithm cannot be null - Password cannot be null. -or- Salt cannot be null. ``` -------------------------------- ### GetBytes Method Declaration Source: https://gpailler.github.io/MegaApiClient/api/Medo.Security.Cryptography.Pbkdf2.html Returns a pseudo-random key from a password, salt, and iteration count. Takes a count parameter for the number of bytes to return. ```csharp public byte[] GetBytes(int count) ``` -------------------------------- ### DownloadFileAsync(INode, String, IProgress, Nullable) Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.MegaApiClient.html Asynchronously downloads a node to a file with progress reporting. ```APIDOC ## DownloadFileAsync(INode, String, IProgress, Nullable) ### Description Asynchronously downloads a node to a file. ### Declaration public Task DownloadFileAsync(INode node, string outputFile, IProgress progress = null, CancellationToken? cancellationToken = null) ### Parameters - **node** (INode) - Required - The node to download - **outputFile** (System.String) - Required - The file to save the node to - **progress** (System.IProgress) - Optional - Progress reporter - **cancellationToken** (System.Nullable) - Optional - Cancellation token ### Returns - **System.Threading.Tasks.Task** - A task representing the asynchronous operation ``` -------------------------------- ### MegaApiClient(IWebClient) Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.MegaApiClient.html Instantiates a new MegaApiClient object with default Options and a custom IWebClient. ```APIDOC ## MegaApiClient(IWebClient) ### Description Instantiates a new MegaApiClient object with default Options and a custom IWebClient. ### Method Constructor ### Signature public MegaApiClient(IWebClient webClient) ### Parameters - **webClient** (IWebClient) - Required - The custom web client to use. ### Returns MegaApiClient instance ``` -------------------------------- ### DownloadAsync(INode, IProgress, Nullable) Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.MegaApiClient.html Asynchronously downloads a node to a stream with progress reporting. ```APIDOC ## DownloadAsync(INode, IProgress, Nullable) ### Description Asynchronously downloads a node to a stream. ### Declaration public Task DownloadAsync(INode node, IProgress progress = null, CancellationToken? cancellationToken = null) ### Parameters - **node** (INode) - Required - The node to download - **progress** (System.IProgress) - Optional - Progress reporter - **cancellationToken** (System.Nullable) - Optional - Cancellation token ### Returns - **System.Threading.Tasks.Task** - A task representing the asynchronous operation, with a result of the downloaded stream ``` -------------------------------- ### DownloadFile(INode, String, Nullable) Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.MegaApiClient.html Downloads a specified node and saves it to the specified file. ```APIDOC ## DownloadFile(INode, String, Nullable) ### Description Download a specified node and save it to the specified file. ### Declaration public void DownloadFile(INode node, string outputFile, CancellationToken? cancellationToken = null) ### Parameters - **node** (INode) - Required - Node to download (only File can be downloaded) - **outputFile** (System.String) - Required - File to save the node to - **cancellationToken** (System.Nullable) - Optional - CancellationToken used to cancel the action ### Exceptions - **System.NotSupportedException** - Not logged in - **ApiException** - Mega.co.nz service reports an error - **System.ArgumentNullException** - node or outputFile is null - **System.ArgumentException** - node is not valid (only File can be downloaded) - **DownloadException** - Checksum is invalid. Downloaded data are corrupted ``` -------------------------------- ### Download folder contents from a Mega link with GetNodesFromLink() Source: https://gpailler.github.io/MegaApiClient/articles/samples.html Downloads all files from a public Mega folder link anonymously. Uses GetNodesFromLink() to list nodes, recreates the folder hierarchy with GetParents() and Directory.CreateDirectory(), then saves each file with DownloadFile(). ```csharp using CG.Web.MegaApiClient; void Main() { MegaApiClient client = new MegaApiClient(); client.LoginAnonymous(); Uri folderLink = new Uri("https://mega.nz/folder/e4diDZ7T#iJnegBO_m6OXBQp27lHCrg"); IEnumerable nodes = client.GetNodesFromLink(folderLink); foreach (INode node in nodes.Where(x => x.Type == NodeType.File)) { string parents = GetParents(node, nodes); Directory.CreateDirectory(parents); Console.WriteLine($"Downloading {parents}\\{node.Name}"); client.DownloadFile(node, Path.Combine(parents, node.Name)); } client.Logout(); } string GetParents(INode node, IEnumerable nodes) { List parents = new List(); while (node.ParentId != null) { INode parentNode = nodes.Single(x => x.Id == node.ParentId); parents.Insert(0, parentNode.Name); node = parentNode; } return string.Join('\\', parents); } ``` -------------------------------- ### Configure link.xml for IL2CPP Source: https://gpailler.github.io/MegaApiClient/index.html Required configuration file when using IL2CPP to ensure the MegaApiClient assembly is preserved. ```xml ``` -------------------------------- ### GenerateAuthInfosAsync(String, String) Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.MegaApiClient.html Asynchronously generates authentication information for the given email and password. ```APIDOC ## GenerateAuthInfosAsync(String, String) ### Description Asynchronously generates authentication information for the given email and password. ### Method GenerateAuthInfosAsync ### Signature public Task GenerateAuthInfosAsync(string email, string password) ### Parameters - **email** (System.String) - Required - The email address. - **password** (System.String) - Required - The password. ### Returns - **Task** - A task representing the asynchronous operation, with the authentication information. ``` -------------------------------- ### Login() Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.MegaApiClient.html Logs in anonymously to the Mega.co.nz service. ```APIDOC ## Login() ### Description Logs in anonymously to the Mega.co.nz service. ### Method Login ### Signature public void Login() ### Exceptions - **ApiException** - Thrown if service is not available. ``` -------------------------------- ### UploadFile(String, INode, Nullable) Source: https://gpailler.github.io/MegaApiClient/api/CG.Web.MegaApiClient.MegaApiClient.html Uploads a file to Mega.co.nz and attaches the created node to the selected parent node. This is a synchronous method that returns the created node. ```APIDOC ## UploadFile(String, INode, Nullable) ### Description Uploads a file on Mega.co.nz and attaches the created node to the selected parent node. ### Method UploadFile ### Declaration public INode UploadFile(string filename, INode parent, CancellationToken? cancellationToken = null) ### Parameters - **filename** (System.String) - Required - File to upload - **parent** (INode) - Required - Node to attach the uploaded file (all types except File are supported) - **cancellationToken** (System.Nullable) - Optional - CancellationToken used to cancel the action ### Returns - **INode** - Created node ### Exceptions - **System.NotSupportedException** - Not logged in - **ApiException** - Mega.co.nz service reports an error - **System.ArgumentNullException** - filename or parent is null - **System.IO.FileNotFoundException** - filename is not found - **System.ArgumentException** - parent is not valid (all types except File are supported) ```