saved a file!
This commit is contained in:
parent
a5bd6eeedb
commit
a45c2b2cf7
@ -4,4 +4,5 @@ version = "0.1.0"
|
|||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
serde_json = "1.0.117"
|
||||||
suppaftp = { version = "6.0.1", features = ["native-tls"] }
|
suppaftp = { version = "6.0.1", features = ["native-tls"] }
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
|
use std::env::temp_dir;
|
||||||
|
use std::path::Path;
|
||||||
|
use serde_json::{Result, Value};
|
||||||
|
|
||||||
use suppaftp::{FtpError, NativeTlsConnector, NativeTlsFtpStream};
|
use suppaftp::{FtpError, NativeTlsConnector, NativeTlsFtpStream};
|
||||||
use suppaftp::native_tls::{Certificate, TlsConnector, TlsStream};
|
use suppaftp::native_tls::{Certificate, TlsConnector};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
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|
|
||||||
panic!("{}", err)
|
panic!("{}", err)
|
||||||
);
|
);
|
||||||
@ -12,13 +16,18 @@ 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());
|
||||||
|
println!("test");
|
||||||
|
let data = ftp_stream.retr_as_buffer("fcs7/versions.json").unwrap();
|
||||||
|
println!("test");
|
||||||
|
let v: Value = serde_json::from_reader(data).unwrap();
|
||||||
|
println!("fcs7/{}",v[0]["File"].as_str().unwrap());
|
||||||
|
let mut data = ftp_stream.retr_as_buffer(format!("fcs7/{}",v[v.as_array().unwrap().len()-1]["File"].as_str().unwrap()).as_str()).unwrap_or_else(|err| panic!("Unable to download file"));
|
||||||
|
println!("{}", temp_dir().join("pack.mrpack").display());
|
||||||
|
let mut file = File::create(temp_dir().join("pack.mrpack")).unwrap();
|
||||||
|
std::io::copy(&mut data, &mut file).unwrap();
|
||||||
|
println!("{}",temp_dir().display());
|
||||||
|
|
||||||
let mut file = File::create("test.txt").unwrap();
|
|
||||||
let mut buf = Vec::new();
|
|
||||||
ftp_stream.retr("modpacks.json", |stream| {
|
|
||||||
stream.read_to_end(&mut buf).map_err(|e| FtpError::ConnectionError(e))
|
|
||||||
}).unwrap();
|
|
||||||
file.write_all(buf.as_slice()).unwrap();
|
|
||||||
|
|
||||||
assert!(ftp_stream.quit().is_ok());
|
assert!(ftp_stream.quit().is_ok());
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user