mirror of
https://git.ahines.net/joeyahines/Albatross.git
synced 2026-11-08 09:13:57 +00:00
Removed FTPS backups and added FTP backups
+ Reverted to ftp 3.0.1 + fmt + clippy
This commit is contained in:
8 files changed
+145
-51
No files matched your search
@@ -1,4 +1,3 @@
|
||||
use ftp::native_tls::TlsConnector;
|
||||
use ftp::FtpStream;
|
||||
use std::path::PathBuf;
|
||||
|
||||
@@ -7,8 +6,8 @@ use crate::error;
|
||||
use crate::error::AlbatrossError;
|
||||
use crate::remote::{PathLocation, RemoteBackupSite};
|
||||
|
||||
/// FTPS Remote Site
|
||||
pub struct FTPSBackup {
|
||||
/// FTP Remote Site
|
||||
pub struct FTPBackup {
|
||||
/// FTP command stream
|
||||
stream: FtpStream,
|
||||
/// Remote target directory
|
||||
@@ -17,44 +16,39 @@ pub struct FTPSBackup {
|
||||
backups_to_keep: usize,
|
||||
}
|
||||
|
||||
impl FTPSBackup {
|
||||
/// New FTPSBackup
|
||||
impl FTPBackup {
|
||||
/// New FTPBackup
|
||||
pub fn new(config: &RemoteBackupConfig) -> error::Result<Self> {
|
||||
let ftps_config = config
|
||||
.ftps
|
||||
let ftp_config = config
|
||||
.ftp
|
||||
.as_ref()
|
||||
.ok_or_else(|| AlbatrossError::RemoteConfigError("FTPS".to_string()))?;
|
||||
.ok_or_else(|| AlbatrossError::RemoteConfigError("FTP".to_string()))?;
|
||||
|
||||
let ctx = TlsConnector::new().unwrap();
|
||||
let (ftp_stream, _) = FtpStream::connect(&ftps_config.server_addr)?;
|
||||
let mut ftp_stream = FtpStream::connect(&ftp_config.server_addr)?;
|
||||
|
||||
let domain = ftps_config
|
||||
.domain
|
||||
.as_ref()
|
||||
.map_or_else(|| "".to_string(), |s| s.clone());
|
||||
let mut ftp_stream = ftp_stream.into_secure(ctx, domain.as_str())?;
|
||||
ftp_stream.login(&ftps_config.username, &ftps_config.password)?;
|
||||
ftp_stream.login(&ftp_config.username, &ftp_config.password)?;
|
||||
|
||||
Ok(Self {
|
||||
stream: ftp_stream,
|
||||
target_dir: ftps_config.remote_dir.clone(),
|
||||
target_dir: ftp_config.remote_dir.clone(),
|
||||
backups_to_keep: config.backups_to_keep as usize,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for FTPSBackup {
|
||||
impl Drop for FTPBackup {
|
||||
fn drop(&mut self) {
|
||||
self.stream.quit().ok();
|
||||
}
|
||||
}
|
||||
|
||||
impl RemoteBackupSite for FTPSBackup {
|
||||
impl RemoteBackupSite for FTPBackup {
|
||||
type FileType = PathLocation;
|
||||
|
||||
fn backup_to_remote(&mut self, file: PathBuf) -> error::Result<()> {
|
||||
let mut local_file = std::fs::File::open(&file)?;
|
||||
let location = self.target_dir.join(file);
|
||||
let location = self.target_dir.join(file.file_name().unwrap());
|
||||
|
||||
self.stream
|
||||
.put(location.to_str().unwrap(), &mut local_file)?;
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ use chrono::NaiveDateTime;
|
||||
use crate::error::Result;
|
||||
|
||||
pub mod file;
|
||||
pub mod ftps;
|
||||
pub mod ftp;
|
||||
pub mod sftp;
|
||||
|
||||
pub trait RemoteBackupFile {
|
||||
|
||||
Reference in new issue
Block a user