mirror of
https://github.com/veeso/termscp.git
synced 2026-06-08 22:28:37 +02:00
Filetransfer trait
This commit is contained in:
99
src/filetransfer/mod.rs
Normal file
99
src/filetransfer/mod.rs
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
//! ## FileTransfer
|
||||||
|
//!
|
||||||
|
//! `filetransfer` is the module which provides the trait file transfers must implement and the different file transfers
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright (C) 2020 Christian Visintin - christian.visintin1997@gmail.com
|
||||||
|
*
|
||||||
|
* This file is part of "TermSCP"
|
||||||
|
*
|
||||||
|
* TermSCP is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* TermSCP is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with TermSCP. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use std::fs::File;
|
||||||
|
|
||||||
|
use crate::fs::FsEntry;
|
||||||
|
|
||||||
|
/// ## FileTransferProtocol
|
||||||
|
///
|
||||||
|
/// This enum defines the different transfer protocol available in TermSCP
|
||||||
|
|
||||||
|
#[derive(PartialEq, Clone)]
|
||||||
|
pub enum FileTransferProtocol {
|
||||||
|
Scp,
|
||||||
|
Sftp,
|
||||||
|
Ftps,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// ## FileTransferError
|
||||||
|
///
|
||||||
|
/// FileTransferError defines the possible errors available for a file transfer
|
||||||
|
|
||||||
|
#[derive(PartialEq, Clone)]
|
||||||
|
pub enum FileTransferError {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// ## FileTransfer
|
||||||
|
///
|
||||||
|
/// File transfer trait must be implemented by all the file transfers and defines the method used by a generic file transfer
|
||||||
|
|
||||||
|
pub trait FileTransfer {
|
||||||
|
|
||||||
|
/// ### connect
|
||||||
|
///
|
||||||
|
/// Connect to the remote server
|
||||||
|
|
||||||
|
fn connect(&mut self, address: String, port: usize, username: Option<String>, password: Option<String>) -> Result<(), FileTransferError>;
|
||||||
|
|
||||||
|
/// ### disconnect
|
||||||
|
///
|
||||||
|
/// Disconnect from the remote server
|
||||||
|
|
||||||
|
fn disconnect(&mut self) -> Result<(), FileTransferError>;
|
||||||
|
|
||||||
|
/// ### pwd
|
||||||
|
///
|
||||||
|
/// Print working directory
|
||||||
|
|
||||||
|
fn pwd(&self) -> Result<PathBuf, FileTransferError>;
|
||||||
|
|
||||||
|
/// ### change_dir
|
||||||
|
///
|
||||||
|
/// Change working directory
|
||||||
|
|
||||||
|
fn change_dir(&mut self, dir: PathBuf) -> Result<PathBuf, FileTransferError>;
|
||||||
|
|
||||||
|
/// ### list_dir
|
||||||
|
///
|
||||||
|
/// List directory entries
|
||||||
|
|
||||||
|
fn list_dir(&self) -> Result<Vec<FsEntry>, FileTransferError>;
|
||||||
|
|
||||||
|
/// ### send_file
|
||||||
|
///
|
||||||
|
/// Send file to remote
|
||||||
|
/// File name is referred to the name of the file as it will be saved
|
||||||
|
/// Data contains the file data
|
||||||
|
fn send_file(&self, file_name: PathBuf, file: File) -> Result<(), FileTransferError>;
|
||||||
|
|
||||||
|
/// ### recv_file
|
||||||
|
///
|
||||||
|
/// Receive file from remote with provided name
|
||||||
|
fn recv_file(&self, file_name: PathBuf) -> Result<Vec<u8>, FileTransferError>;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -26,6 +26,15 @@
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
|
/// ## FsEntry
|
||||||
|
///
|
||||||
|
/// FsEntry represents a generic entry in a directory
|
||||||
|
|
||||||
|
pub enum FsEntry {
|
||||||
|
Directory(FsDirectory),
|
||||||
|
File(FsFile)
|
||||||
|
}
|
||||||
|
|
||||||
/// ## FsDirectory
|
/// ## FsDirectory
|
||||||
///
|
///
|
||||||
/// Directory provides an interface to file system directories
|
/// Directory provides an interface to file system directories
|
||||||
|
|||||||
25
src/host/mod.rs
Normal file
25
src/host/mod.rs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
//! ## Host
|
||||||
|
//!
|
||||||
|
//! `host` is the module which provides functionalities to host file system
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright (C) 2020 Christian Visintin - christian.visintin1997@gmail.com
|
||||||
|
*
|
||||||
|
* This file is part of "TermSCP"
|
||||||
|
*
|
||||||
|
* TermSCP is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* TermSCP is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with TermSCP. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
@@ -18,3 +18,7 @@
|
|||||||
* along with TermSCP. If not, see <http://www.gnu.org/licenses/>.
|
* along with TermSCP. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
pub mod filetransfer;
|
||||||
|
pub mod fs;
|
||||||
|
pub mod host;
|
||||||
|
|||||||
Reference in New Issue
Block a user