Rust

Control Rclone from Rust using the remote control HTTP API with reqwest.

Rust's reqwest crate is the de facto standard for HTTP requests, offering both async and blocking APIs for interacting with Rclone's remote control API.

Usage

Using async reqwest: The async API runs inside a Tokio runtime. The sample fetches the root of the API, reads the body as text and prints it:

use reqwest;

#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
    let response = reqwest::get("http://localhost:5572/")
        .await?
        .text()
        .await?;
    println!("{}", response);
    Ok(())
}

Using blocking reqwest:

use reqwest::blocking;

fn main() -> Result<(), reqwest::Error> {
    let response = blocking::get("http://localhost:5572/")?
        .text()?;
    println!("{}", response);
    Ok(())
}

Libraries

rclone-sdk

A fully typed SDK for Rclone's remote control API, generated from OpenAPI.

[dependencies]
rclone-sdk = "1.72"
tokio = { version = "1", features = ["full"] }

The sample creates a client for the local daemon, prints the Rclone version with its OS and architecture, lists the configured remotes, and prints the used and total storage of the gdrive: remote:

use rclone_sdk::Client;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new("http://localhost:5572");

    // Get rclone version info
    let version = client.core_version(None, None).await?;
    let v = version.into_inner();
    println!("Rclone {} on {}/{}", v.version, v.os, v.arch);

    // List all configured remotes
    let remotes = client.config_listremotes(None, None).await?;
    println!("Remotes: {:?}", remotes.into_inner().remotes);

    // Get storage info for a remote
    let about = client.operations_about(None, None, "gdrive:").await?;
    let info = about.into_inner();
    println!("Storage: {} / {} bytes used", info.used, info.total);

    Ok(())
}

How is this guide?