remote-fs 0.1.1

Unified async file operations over SMB, FTP, and SFTP
Documentation
use std::path::Path;

use async_trait::async_trait;

use crate::error::Result;
use crate::types::{FileEntry, FileMeta};

/// Unified async remote file system operations.
#[async_trait]
pub trait RemoteFileSystem: Send {
    /// Connect to the remote server.
    async fn connect(&mut self) -> Result<()>;

    /// Disconnect from the remote server.
    async fn disconnect(&mut self) -> Result<()>;

    /// Whether the client is currently connected.
    fn is_connected(&self) -> bool;

    /// List entries under `path`.
    async fn list(&mut self, path: &str) -> Result<Vec<FileEntry>>;

    /// Get metadata for `path`.
    async fn metadata(&mut self, path: &str) -> Result<FileMeta>;

    /// Check whether `path` exists.
    async fn exists(&mut self, path: &str) -> Result<bool>;

    /// Create a directory at `path`.
    async fn mkdir(&mut self, path: &str) -> Result<()>;

    /// Create directories recursively.
    async fn mkdir_all(&mut self, path: &str) -> Result<()>;

    /// Remove an empty directory.
    async fn rmdir(&mut self, path: &str) -> Result<()>;

    /// Remove a file.
    async fn remove_file(&mut self, path: &str) -> Result<()>;

    /// Remove a file or directory recursively.
    async fn remove(&mut self, path: &str) -> Result<()>;

    /// Rename / move a path.
    async fn rename(&mut self, from: &str, to: &str) -> Result<()>;

    /// Read entire file into memory.
    async fn read(&mut self, path: &str) -> Result<Vec<u8>>;

    /// Write entire file from memory.
    async fn write(&mut self, path: &str, data: &[u8]) -> Result<()>;

    /// Download remote file to local path.
    async fn download(&mut self, remote: &str, local: &Path) -> Result<()>;

    /// Upload local file to remote path.
    async fn upload(&mut self, local: &Path, remote: &str) -> Result<()>;
}