UgosProApi 1.0.0

dotnet add package UgosProApi --version 1.0.0
                    
NuGet\Install-Package UgosProApi -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="UgosProApi" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="UgosProApi" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="UgosProApi" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add UgosProApi --version 1.0.0
                    
#r "nuget: UgosProApi, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package UgosProApi@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=UgosProApi&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=UgosProApi&version=1.0.0
                    
Install as a Cake Tool

UgosProApi

绿联 UGOS Pro NAS 系统的非官方 .NET SDK 客户端。

通过对绿联 UGOS Pro Web 前端的私有 API 进行逆向工程实现,提供安全登录、会话管理、文件列表、上传、下载和删除功能。

安装

dotnet add package UgosProApi

快速开始

基础用法

using UgosProApi;
using UgosProApi.Authentication;

// 配置 NAS 连接
var config = new UgosConfig
{
    Protocol = "https://",
    Server = "192.168.1.1",
    Port = 9999,
    Username = "admin",
    Password = "your_password"
};

// 创建客户端
using var client = new UgosClient(config);

// 1. 获取 RSA 公钥
var rsaPublicKey = await client.GetPasswordRsaAsync();

// 2. 登录
var session = await client.LoginAsync(rsaPublicKey);

// 3. 刷新会话
await client.IsLoginAsync(session);

// 4. 上传文件
var fileBytes = File.ReadAllBytes(@"C:\test.jpg");
await client.UploadFileAsync(session, fileBytes, "test.jpg",
    DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), "/home/admin/");

// 5. 下载文件
await using var stream = await client.DownloadAsync(session,
    new List<string> { "/home/admin/test.jpg" });
using var fileStream = File.Create(@"C:\downloaded.jpg");
await stream.CopyToAsync(fileStream);

// 6. 删除文件(移入回收站)
await client.DeletePathsAsync(session,
    new List<string> { "/home/admin/test.jpg" }, forever: false);

ASP.NET Core DI 集成

// Program.cs
builder.Services.AddUgosProApi(config =>
{
    config.Server = "192.168.1.1";
    config.Port = 9999;
    config.Username = "admin";
    config.Password = "your_password";
});

// 在 Controller / Service 中使用
public class FileController : ControllerBase
{
    private readonly IUgosClient _ugosClient;

    public FileController(IUgosClient ugosClient)
    {
        _ugosClient = ugosClient;
    }

    [HttpPost("upload")]
    public async Task<IActionResult> Upload(IFormFile file)
    {
        var rsaKey = await _ugosClient.GetPasswordRsaAsync();
        var session = await _ugosClient.LoginAsync(rsaKey);

        using var ms = new MemoryStream();
        await file.CopyToAsync(ms);
        var bytes = ms.ToArray();

        await _ugosClient.UploadFileAsync(session, bytes, file.FileName,
            DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), "/home/admin/");

        return Ok();
    }
}

API 参考

方法 说明
GetPasswordRsaAsync(ct) 获取 RSA 公钥,用于登录密码加密
LoginAsync(pemBase64, ct) 登录 NAS,返回会话凭证
IsLoginAsync(container, ct) 刷新会话 Cookie,防止过期
ListDirAsync(container, ct) 列出目录内容
UploadFileAsync(container, data, filename, changeTime, dir, ct) 上传文件(三步流程)
DownloadAsync(container, paths, ct) 下载文件,返回 Stream
DeletePathsAsync(container, paths, forever, ct) 删除文件或目录

认证流程

  1. 获取 RSA 公钥POST /ugreen/v1/verify/check
  2. 密码登录:RSA 加密密码后 POST /ugreen/v1/verify/login
  3. 请求签名:后续请求携带 cookiex-ugreen-security-keyx-ugreen-token 请求头
  4. 会话刷新:定期调用 IsLoginAsync 更新 Cookie

目标框架

  • .NET 8.0+

依赖

  • 仅依赖 Microsoft.Extensions.DependencyInjection.Abstractions(可选,仅 DI 集成需要)

许可证

MIT

致谢

本项目基于 Java 原版 ugos_pro_api 移植,感谢原作者 pewee。

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 97 5/11/2026