Filetransfer trait

This commit is contained in:
ChristianVisintin 2020-11-08 11:02:43 +01:00
parent 045a72f2de
commit 606a3f96f5
4 changed files with 137 additions and 0 deletions

99
src/filetransfer/mod.rs Normal file
View 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>;
}

View file

@ -26,6 +26,15 @@
use std::path::PathBuf;
use std::time::Instant;
/// ## FsEntry
///
/// FsEntry represents a generic entry in a directory
pub enum FsEntry {
Directory(FsDirectory),
File(FsFile)
}
/// ## FsDirectory
///
/// Directory provides an interface to file system directories

25
src/host/mod.rs Normal file
View 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/>.
*
*/

View file

@ -18,3 +18,7 @@
* along with TermSCP. If not, see <http://www.gnu.org/licenses/>.
*
*/
pub mod filetransfer;
pub mod fs;
pub mod host;