working on basic ftp implementation

This commit is contained in:
Samuel Walker 2024-06-21 23:17:56 -06:00
parent a45c2b2cf7
commit be43b49838
2 changed files with 21 additions and 0 deletions

18
launcher/src/ftp.rs Normal file
View File

@ -0,0 +1,18 @@
use suppaftp::FtpError;
use suppaftp::NativeTlsFtpStream;
use suppaftp::NativeTlsConnector;
use suppaftp::native_tls::Certificate;
use suppaftp::native_tls::TlsConnector;
fn ftpConnection() -> Result<NativeTlsFtpStream, FtpError>{
let ftp_stream = NativeTlsFtpStream::connect("gitea.piwalker.net:21").unwrap_or_else(|err|
panic!("{}", err)
);
let cert = include_bytes!("../res/vsftpd.crt");
let cert = Certificate::from_pem(cert).unwrap();
let mut ftp_stream = ftp_stream.into_secure(NativeTlsConnector::from(TlsConnector::builder().add_root_certificate(cert).build().unwrap()), "gitea.piwalker.net").unwrap();
ftp_stream.login("anonymous", "anonymous@").map(|_| Ok(ftp_stream)).unwrap()
}

View File

@ -7,6 +7,8 @@ use serde_json::{Result, Value};
use suppaftp::{FtpError, NativeTlsConnector, NativeTlsFtpStream}; use suppaftp::{FtpError, NativeTlsConnector, NativeTlsFtpStream};
use suppaftp::native_tls::{Certificate, TlsConnector}; use suppaftp::native_tls::{Certificate, TlsConnector};
mod ftp;
fn main() { fn main() {
println!("test"); println!("test");
let ftp_stream = NativeTlsFtpStream::connect("gitea.piwalker.net:21").unwrap_or_else(|err| let ftp_stream = NativeTlsFtpStream::connect("gitea.piwalker.net:21").unwrap_or_else(|err|
@ -16,6 +18,7 @@ fn main() {
let cert = Certificate::from_pem(cert).unwrap(); let cert = Certificate::from_pem(cert).unwrap();
let mut ftp_stream = ftp_stream.into_secure(NativeTlsConnector::from(TlsConnector::builder().add_root_certificate(cert).build().unwrap()), "gitea.piwalker.net").unwrap(); let mut ftp_stream = ftp_stream.into_secure(NativeTlsConnector::from(TlsConnector::builder().add_root_certificate(cert).build().unwrap()), "gitea.piwalker.net").unwrap();
assert!(ftp_stream.login("anonymous", "anonymous@").is_ok()); assert!(ftp_stream.login("anonymous", "anonymous@").is_ok());
assert!(ftp_stream.size("test").is_ok());
println!("test"); println!("test");
let data = ftp_stream.retr_as_buffer("fcs7/versions.json").unwrap(); let data = ftp_stream.retr_as_buffer("fcs7/versions.json").unwrap();
println!("test"); println!("test");