Ecng system framework
$ dotnet add package Ecng.Backup.YandexYandex.Disk backup provider implementing IBackupService.
YandexDiskService provides cloud backup capabilities using Yandex.Disk cloud storage service.
using System.Security;
using Ecng.Backup;
using Ecng.Backup.Yandex;
// Create secure token
var token = new SecureString();
foreach (char c in "your-oauth-token")
token.AppendChar(c);
token.MakeReadOnly();
var yandex = new YandexDiskService(token);
| Feature | Supported |
|---|---|
| CanPublish | Yes (permanent links only) |
| CanExpirable | No |
| CanFolders | Yes |
| CanPartialDownload | No |
// Create nested folder structure
var folder = new BackupEntry { Name = "backups" };
var subfolder = new BackupEntry { Name = "2024", Parent = folder };
// Creates /backups/2024
await yandex.CreateFolder(subfolder);
// Parent folders are created automatically if they don't exist
var entry = new BackupEntry { Name = "backups/2024/data.zip" };
await using var stream = File.OpenRead(@"C:\data.zip");
await yandex.UploadAsync(entry, stream, progress =>
{
// Note: Progress may not be reported for all uploads
Console.WriteLine($"Upload: {progress}%");
});
var entry = new BackupEntry { Name = "backups/2024/data.zip" };
await using var stream = File.Create(@"C:\downloaded-data.zip");
await yandex.DownloadAsync(entry, stream, null, null, progress =>
{
Console.WriteLine($"Download: {progress}%");
});
// Note: Partial downloads are not supported
// List files in folder (with pagination handled automatically)
var folder = new BackupEntry { Name = "backups/2024" };
await foreach (var item in yandex.FindAsync(folder, criteria: null))
{
Console.WriteLine($"{item.Name}: {item.Size} bytes");
Console.WriteLine($" Modified: {item.LastModified}");
}
// List root folder
await foreach (var item in yandex.FindAsync(null, criteria: null))
{
Console.WriteLine(item.Name);
}
// Filter by name
await foreach (var item in yandex.FindAsync(folder, criteria: ".zip"))
{
Console.WriteLine(item.Name); // Only items containing ".zip"
}var entry = new BackupEntry { Name = "shared/document.pdf" };
// Get public share link
string publicUrl = await yandex.PublishAsync(entry);
Console.WriteLine($"Share link: {publicUrl}");
// Remove public access
await yandex.UnPublishAsync(entry);var entry = new BackupEntry { Name = "backups/old-backup.zip" };
await yandex.DeleteAsync(entry);var entry = new BackupEntry { Name = "backups/data.zip" };
await yandex.FillInfoAsync(entry);
Console.WriteLine($"Size: {entry.Size}");
Console.WriteLine($"Modified: {entry.LastModified}");Yandex.Disk uses forward slashes for paths:
/backups/2024backups/2024/data.ziptry
{
await yandex.FillInfoAsync(entry);
}
catch (YandexApiException ex) when (ex.StatusCode == HttpStatusCode.NotFound)
{
Console.WriteLine("File not found");
}Install-Package Ecng.Backup.Yandex