2023-10-02 22:04:41 +03:00
|
|
|
use std::fs::{File, Metadata, self};
|
2023-09-17 07:28:18 +03:00
|
|
|
use std::time::Instant;
|
2023-09-14 08:29:32 +03:00
|
|
|
use std::net::{TcpListener, TcpStream};
|
2023-10-10 02:13:26 +03:00
|
|
|
use std::io::{Read, Write, self, BufWriter, BufReader, BufRead};
|
2023-09-16 19:15:30 +03:00
|
|
|
use std::env::{self};
|
2023-09-14 08:29:32 +03:00
|
|
|
|
2023-10-08 15:18:37 +03:00
|
|
|
|
2023-10-12 13:52:08 +03:00
|
|
|
const BUFFER_SIZE:usize = 512;
|
2023-10-08 15:18:37 +03:00
|
|
|
|
2023-09-16 19:15:30 +03:00
|
|
|
struct FileInfo
|
2023-09-14 08:29:32 +03:00
|
|
|
{
|
2023-09-16 19:15:30 +03:00
|
|
|
file:Option<File>,
|
|
|
|
location:String,
|
2023-10-08 01:52:42 +03:00
|
|
|
size_current:usize,
|
2023-10-02 22:04:41 +03:00
|
|
|
metadata:Option<Metadata>,
|
2023-09-14 08:29:32 +03:00
|
|
|
}
|
2023-09-16 19:15:30 +03:00
|
|
|
impl FileInfo
|
2023-09-14 08:29:32 +03:00
|
|
|
{
|
2023-10-08 01:52:42 +03:00
|
|
|
fn reading_operations(&mut self, stream:&mut TcpStream)
|
2023-09-29 01:44:25 +03:00
|
|
|
{
|
2023-10-02 22:04:41 +03:00
|
|
|
self.read_metadata();
|
|
|
|
match self.metadata
|
|
|
|
{
|
|
|
|
Some(ref mut metadata) =>
|
|
|
|
{
|
|
|
|
if Metadata::is_file(metadata)
|
|
|
|
{
|
|
|
|
self.read_file();
|
2023-10-08 15:18:37 +03:00
|
|
|
self.file_to_byte(stream);
|
2023-10-02 22:04:41 +03:00
|
|
|
}
|
|
|
|
else if Metadata::is_symlink(metadata)
|
|
|
|
{
|
|
|
|
self.read_file();
|
2023-10-08 15:18:37 +03:00
|
|
|
self.file_to_byte(stream);
|
2023-10-02 22:04:41 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//path recognition and creation on the other side
|
|
|
|
//std:path
|
|
|
|
panic!("\n\tError: Folder Transfers've not Supported yet\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
None =>
|
2023-10-08 01:52:42 +03:00
|
|
|
{
|
|
|
|
println!("Error: Read Metadata -> {}", self.location);
|
|
|
|
}
|
|
|
|
}
|
2023-09-29 01:44:25 +03:00
|
|
|
}
|
2023-10-08 01:52:42 +03:00
|
|
|
fn writing_operations(&mut self, stream:&mut TcpStream)
|
2023-09-29 01:44:25 +03:00
|
|
|
{
|
2023-10-08 15:18:37 +03:00
|
|
|
self.write_file(stream);
|
2023-09-29 01:44:25 +03:00
|
|
|
}
|
2023-10-02 22:04:41 +03:00
|
|
|
fn read_metadata(&mut self)
|
|
|
|
{
|
2023-10-08 01:52:42 +03:00
|
|
|
//use match, there is a chance to fail creation. don't pass with just some
|
2023-10-02 22:04:41 +03:00
|
|
|
self.metadata = Some(fs::metadata(&self.location).expect("Error: Read Metadata"));
|
|
|
|
}
|
2023-09-16 19:15:30 +03:00
|
|
|
fn read_file(&mut self)
|
|
|
|
{
|
2023-10-08 01:52:42 +03:00
|
|
|
match File::open(&self.location)
|
|
|
|
{
|
|
|
|
Ok(file) =>
|
|
|
|
{
|
|
|
|
self.file = Some(file);
|
|
|
|
}
|
|
|
|
Err(err_val) =>
|
|
|
|
{
|
|
|
|
println!("Error: Open File -> {} | Error: {}", self.location, err_val);
|
2023-10-12 02:54:57 +03:00
|
|
|
return;
|
2023-10-08 01:52:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-16 19:15:30 +03:00
|
|
|
}
|
2023-10-08 01:52:42 +03:00
|
|
|
fn file_to_byte(&mut self, stream:&mut TcpStream)
|
2023-10-11 02:54:21 +03:00
|
|
|
{
|
2023-10-08 15:18:37 +03:00
|
|
|
let mut iteration = (self.metadata.as_ref().unwrap().len()/BUFFER_SIZE as u64)+1;
|
2023-10-11 02:54:21 +03:00
|
|
|
let mut stream_writer = BufWriter::new(stream.try_clone().unwrap());
|
|
|
|
let mut stream_reader = BufReader::new(stream.try_clone().unwrap());
|
|
|
|
match stream_writer.write_all(self.metadata.as_ref().unwrap().len().to_string().as_bytes())
|
2023-10-09 01:51:15 +03:00
|
|
|
{
|
|
|
|
Ok(_) =>
|
|
|
|
{
|
2023-10-11 02:54:21 +03:00
|
|
|
match stream_writer.write_all(String::from("\n").as_bytes())
|
|
|
|
{
|
|
|
|
Ok(_) =>
|
|
|
|
{
|
|
|
|
println!("Done: Send Terminator -> {}", self.location);
|
|
|
|
}
|
|
|
|
Err(err_val) =>
|
|
|
|
{
|
|
|
|
println!("Error: Send Terminator -> {} | Error: {}", self.location, err_val);
|
2023-10-12 02:54:57 +03:00
|
|
|
return;
|
2023-10-11 02:54:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
match stream_writer.flush()
|
2023-10-10 02:13:26 +03:00
|
|
|
{
|
|
|
|
Ok(_) =>
|
|
|
|
{
|
|
|
|
println!("Done: Flush Handshake -> {}", self.location);
|
|
|
|
}
|
|
|
|
Err(err_val) =>
|
|
|
|
{
|
|
|
|
println!("Error: Flush Handshake -> {} | Error: {}", self.location, err_val);
|
2023-10-12 02:54:57 +03:00
|
|
|
return;
|
2023-10-10 02:13:26 +03:00
|
|
|
}
|
|
|
|
}
|
2023-10-11 02:54:21 +03:00
|
|
|
let mut handshake_callback:Vec<u8> = Vec::new();
|
|
|
|
match stream_reader.read_until( b'\n',&mut handshake_callback)
|
2023-10-09 01:51:15 +03:00
|
|
|
{
|
|
|
|
Ok(_) =>
|
|
|
|
{
|
2023-10-11 02:54:21 +03:00
|
|
|
println!("Done: Handshake Callback -> {}", self.location);
|
|
|
|
handshake_callback.pop();
|
|
|
|
if handshake_callback.as_slice() == self.metadata.as_ref().unwrap().len().to_string().as_bytes()
|
|
|
|
{
|
|
|
|
println!("Done: Handshake Correct -> {}", self.location);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
println!("Error: Handshake Incorrect -> {}", self.location);
|
|
|
|
return;
|
|
|
|
}
|
2023-10-09 01:51:15 +03:00
|
|
|
}
|
|
|
|
Err(err_val) =>
|
|
|
|
{
|
|
|
|
println!("Error: Handshake Recv -> {} | Error: {}", self.location, err_val);
|
2023-10-11 02:54:21 +03:00
|
|
|
return;
|
2023-10-09 01:51:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Err(err_val) =>
|
|
|
|
{
|
|
|
|
println!("Error: Handshake Send -> {} | Error: {}", self.location, err_val);
|
2023-10-10 02:13:26 +03:00
|
|
|
return;
|
2023-10-09 01:51:15 +03:00
|
|
|
}
|
|
|
|
}
|
2023-10-11 02:54:21 +03:00
|
|
|
println!("Size = {}", self.metadata.as_ref().unwrap().len());
|
|
|
|
println!("Iteration = {}", iteration);
|
2023-10-08 15:18:37 +03:00
|
|
|
while iteration != 0
|
2023-09-16 19:15:30 +03:00
|
|
|
{
|
2023-10-08 15:18:37 +03:00
|
|
|
iteration -= 1;
|
2023-10-12 13:52:08 +03:00
|
|
|
let mut buffer = [0u8;BUFFER_SIZE];
|
2023-10-10 02:13:26 +03:00
|
|
|
let mut file_reader = BufReader::new(self.file.as_ref().unwrap());
|
2023-10-12 13:52:08 +03:00
|
|
|
if iteration != 0
|
2023-09-16 19:15:30 +03:00
|
|
|
{
|
2023-10-12 13:52:08 +03:00
|
|
|
match file_reader.read_exact(&mut buffer)
|
2023-09-16 19:15:30 +03:00
|
|
|
{
|
2023-10-12 13:52:08 +03:00
|
|
|
Ok(_) =>
|
2023-10-10 02:13:26 +03:00
|
|
|
{
|
2023-10-12 13:52:08 +03:00
|
|
|
self.size_current += buffer.len();
|
|
|
|
println!("Size now = {}", self.size_current);
|
|
|
|
//println!("{} | {} | {:#?}", iteration,buffer.len(), buffer);
|
|
|
|
|
2023-10-11 02:54:21 +03:00
|
|
|
}
|
2023-10-12 13:52:08 +03:00
|
|
|
Err(err_val) =>
|
2023-10-11 02:54:21 +03:00
|
|
|
{
|
2023-10-12 13:52:08 +03:00
|
|
|
println!("Error: File to Byte -> {} | Error: {}", self.location, err_val);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
let mut last_buffer:Vec<u8> = Vec::new();
|
|
|
|
match file_reader.read_to_end(&mut last_buffer)
|
|
|
|
{
|
|
|
|
Ok(read_size) =>
|
|
|
|
{
|
|
|
|
self.size_current += read_size;
|
|
|
|
last_buffer.append(&mut buffer[..(self.metadata.as_ref().unwrap().len()%BUFFER_SIZE as u64) as usize].to_vec());
|
|
|
|
buffer.copy_from_slice(&last_buffer);
|
|
|
|
println!("Size now = {}", self.size_current);
|
|
|
|
//println!("{} | {} | {:#?}", iteration,buffer.len(), buffer);
|
2023-10-10 02:13:26 +03:00
|
|
|
}
|
2023-10-12 13:52:08 +03:00
|
|
|
Err(err_val) =>
|
|
|
|
{
|
|
|
|
println!("Error: File to Byte Last -> {} | Error: {}", self.location, err_val);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
match stream_writer.write_all(&mut buffer)
|
|
|
|
{
|
|
|
|
Ok(_) =>
|
|
|
|
{
|
|
|
|
println!("Done: Send Bytes -> {} | Iteration = {}", self.location, iteration);
|
|
|
|
}
|
|
|
|
Err(err_val) =>
|
|
|
|
{
|
|
|
|
println!("Error: Send Bytes -> {} | Error: {}", self.location, err_val);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
match stream_writer.flush()
|
|
|
|
{
|
|
|
|
Ok(_) =>
|
|
|
|
{
|
|
|
|
//println!("Done: Flush -> {}", self.location);
|
2023-10-08 15:18:37 +03:00
|
|
|
}
|
|
|
|
Err(err_val) =>
|
|
|
|
{
|
2023-10-12 13:52:08 +03:00
|
|
|
println!("Error: Flush -> {} | Error: {}", self.location, err_val);
|
2023-10-12 02:54:57 +03:00
|
|
|
return;
|
2023-09-16 19:15:30 +03:00
|
|
|
}
|
|
|
|
}
|
2023-10-08 15:18:37 +03:00
|
|
|
|
|
|
|
|
2023-09-16 19:15:30 +03:00
|
|
|
}
|
|
|
|
}
|
2023-10-08 15:18:37 +03:00
|
|
|
fn write_file(&mut self, stream:&mut TcpStream)
|
2023-09-14 08:29:32 +03:00
|
|
|
{
|
2023-10-08 01:52:42 +03:00
|
|
|
//use match, there is a chance to fail creation. don't pass with just some
|
2023-09-16 19:15:30 +03:00
|
|
|
self.file = Some(File::create(&self.location).expect("Error: Create File"));
|
2023-10-10 02:13:26 +03:00
|
|
|
let mut file_writer = BufWriter::new(self.file.as_ref().unwrap());
|
|
|
|
let mut stream_reader = BufReader::new(stream.try_clone().unwrap());
|
|
|
|
let mut stream_writer = BufWriter::new(stream.try_clone().unwrap());
|
2023-10-11 02:54:21 +03:00
|
|
|
let size:u64;
|
2023-10-10 02:13:26 +03:00
|
|
|
let mut handshake:Vec<u8> = Vec::new();
|
|
|
|
match stream_reader.read_until(b'\n',&mut handshake)
|
2023-09-16 19:15:30 +03:00
|
|
|
{
|
2023-10-10 02:13:26 +03:00
|
|
|
Ok(_) =>
|
2023-09-16 19:15:30 +03:00
|
|
|
{
|
2023-10-10 02:13:26 +03:00
|
|
|
//read until and take
|
2023-10-11 02:54:21 +03:00
|
|
|
handshake.pop();
|
|
|
|
size = String::from_utf8(handshake.clone()).unwrap().parse().unwrap();
|
2023-10-10 02:13:26 +03:00
|
|
|
println!("Done: Handshake Recv -> {}", self.location);
|
2023-10-11 02:54:21 +03:00
|
|
|
match stream_writer.write_all(&mut handshake)
|
2023-09-16 19:15:30 +03:00
|
|
|
{
|
2023-09-16 22:08:10 +03:00
|
|
|
Ok(_) =>
|
|
|
|
{
|
2023-10-10 02:13:26 +03:00
|
|
|
println!("Done: Handshake Send -> {}", self.location);
|
2023-09-16 22:08:10 +03:00
|
|
|
}
|
2023-10-08 15:18:37 +03:00
|
|
|
Err(err_val) =>
|
|
|
|
{
|
2023-10-10 02:13:26 +03:00
|
|
|
println!("Error: Handshake Send -> {} | Error: {}", self.location, err_val);
|
2023-10-11 02:54:21 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
match stream_writer.write_all(String::from("\n").as_bytes())
|
|
|
|
{
|
|
|
|
Ok(_) =>
|
|
|
|
{
|
|
|
|
println!("Done: Send Terminator -> {}", self.location);
|
|
|
|
}
|
|
|
|
Err(err_val) =>
|
|
|
|
{
|
|
|
|
println!("Error: Send Terminator -> {} | Error: {}", self.location, err_val);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
match stream_writer.flush()
|
|
|
|
{
|
|
|
|
Ok(_) =>
|
|
|
|
{
|
|
|
|
println!("Done: Flush -> {}", self.location);
|
|
|
|
}
|
|
|
|
Err(err_val) =>
|
|
|
|
{
|
|
|
|
println!("Error: Flush -> {} | Error: {}", self.location, err_val);
|
|
|
|
return;
|
2023-10-08 15:18:37 +03:00
|
|
|
}
|
2023-10-09 01:51:15 +03:00
|
|
|
}
|
2023-09-16 19:15:30 +03:00
|
|
|
}
|
2023-10-10 02:13:26 +03:00
|
|
|
Err(err_val) =>
|
2023-09-16 19:15:30 +03:00
|
|
|
{
|
2023-10-10 02:13:26 +03:00
|
|
|
println!("Error: Handshake Recv -> {} | Error: {}", self.location, err_val);
|
2023-10-11 02:54:21 +03:00
|
|
|
return;
|
2023-09-16 19:15:30 +03:00
|
|
|
}
|
|
|
|
}
|
2023-10-11 02:54:21 +03:00
|
|
|
let mut iteration:u64 = (size/BUFFER_SIZE as u64)+1;
|
|
|
|
println!("Size = {}", size);
|
|
|
|
println!("Iteration = {}", iteration);
|
2023-10-10 02:13:26 +03:00
|
|
|
while iteration != 0
|
|
|
|
{
|
|
|
|
iteration -= 1;
|
2023-10-12 02:54:57 +03:00
|
|
|
let mut buffer = [0u8;BUFFER_SIZE];
|
2023-10-11 02:54:21 +03:00
|
|
|
match stream_reader.read_exact(&mut buffer)
|
2023-10-10 02:13:26 +03:00
|
|
|
{
|
|
|
|
Ok(_) =>
|
|
|
|
{
|
2023-10-12 02:54:57 +03:00
|
|
|
self.size_current += buffer.len();
|
2023-10-12 13:52:08 +03:00
|
|
|
println!("{} | {:#?}", iteration, buffer);
|
2023-10-11 02:54:21 +03:00
|
|
|
if iteration != 0
|
|
|
|
{
|
|
|
|
match file_writer.write_all(&mut buffer)
|
|
|
|
{
|
|
|
|
Ok(_) =>
|
|
|
|
{
|
2023-10-12 02:54:57 +03:00
|
|
|
println!("Done: Write -> {} bytes | Iteration = {}", &mut self.size_current, iteration);
|
|
|
|
}
|
|
|
|
Err(err_val) =>
|
|
|
|
{
|
|
|
|
println!("Error: Write -> {} | Error: {}", self.location,err_val);
|
|
|
|
return;
|
2023-10-11 02:54:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2023-10-12 02:54:57 +03:00
|
|
|
{
|
|
|
|
match file_writer.write_all(&mut buffer[..(size%BUFFER_SIZE as u64)as usize])
|
2023-10-11 02:54:21 +03:00
|
|
|
{
|
|
|
|
Ok(_) =>
|
|
|
|
{
|
2023-10-12 02:54:57 +03:00
|
|
|
println!("Done: Write Last -> {} bytes | Iteration = {}", &mut self.size_current, iteration);
|
2023-10-11 02:54:21 +03:00
|
|
|
}
|
|
|
|
Err(err_val) =>
|
|
|
|
{
|
2023-10-12 02:54:57 +03:00
|
|
|
println!("Error: Write Last -> {} | Error: {}", self.location,err_val);
|
|
|
|
return;
|
2023-10-11 02:54:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-10-10 02:13:26 +03:00
|
|
|
}
|
|
|
|
Err(err_val) =>
|
|
|
|
{
|
2023-10-12 02:54:57 +03:00
|
|
|
println!("{} | {:#?}", iteration, buffer);
|
2023-10-10 02:13:26 +03:00
|
|
|
println!("Error: Recv Bytes -> {} | Error: {}", self.location, err_val);
|
2023-10-12 02:54:57 +03:00
|
|
|
return;
|
2023-10-10 02:13:26 +03:00
|
|
|
}
|
2023-10-12 02:54:57 +03:00
|
|
|
}
|
2023-10-10 02:13:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-09-14 08:29:32 +03:00
|
|
|
}
|
|
|
|
}
|
2023-09-16 19:15:30 +03:00
|
|
|
enum Connection
|
|
|
|
{
|
|
|
|
Server(String, String),
|
|
|
|
Client(String, String),
|
|
|
|
}
|
|
|
|
impl Connection
|
2023-09-14 08:29:32 +03:00
|
|
|
{
|
2023-09-16 19:15:30 +03:00
|
|
|
fn server(self, file_info:&mut FileInfo)
|
|
|
|
{
|
2023-10-02 22:04:41 +03:00
|
|
|
print!("Server -> ");
|
2023-09-16 19:15:30 +03:00
|
|
|
let ip:String;
|
|
|
|
let port:String;
|
|
|
|
let address:String;
|
|
|
|
match self
|
|
|
|
{
|
|
|
|
Connection::Server(in1, in2) =>
|
|
|
|
{
|
|
|
|
ip = in1.trim_end().to_string();
|
|
|
|
port = in2.trim_end().to_string();
|
|
|
|
address = format!("{}:{}", ip, port);
|
|
|
|
println!("{}", address);
|
|
|
|
}
|
|
|
|
_ => return
|
|
|
|
}
|
|
|
|
let socket = TcpListener::bind(address);
|
|
|
|
for stream in socket.expect("Error: Can't Check Connections").incoming()
|
|
|
|
{
|
|
|
|
match stream
|
|
|
|
{
|
|
|
|
Ok(mut stream) =>
|
|
|
|
{
|
2023-10-08 15:18:37 +03:00
|
|
|
let mut stay = true;
|
2023-09-16 19:15:30 +03:00
|
|
|
while stay
|
|
|
|
{
|
2023-09-17 07:28:18 +03:00
|
|
|
let start_time = Instant::now();
|
2023-10-08 15:18:37 +03:00
|
|
|
FileInfo::writing_operations(file_info, &mut stream);
|
|
|
|
let finish_time = Instant::now();
|
|
|
|
println!("Passed: Total -> {:#?}", finish_time.duration_since(start_time));
|
|
|
|
stay = false;
|
2023-09-16 19:15:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Err(e) =>
|
|
|
|
{
|
|
|
|
println!("Error: Can't Visit Stream -> {}", e);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn client(self, file_info:&mut FileInfo)
|
2023-09-14 08:29:32 +03:00
|
|
|
{
|
2023-10-02 22:04:41 +03:00
|
|
|
print!("Client -> ");
|
2023-09-16 19:15:30 +03:00
|
|
|
let ip:String;
|
|
|
|
let port:String;
|
|
|
|
let address:String;
|
|
|
|
match self
|
|
|
|
{
|
|
|
|
Connection::Client(in1, in2) =>
|
|
|
|
{
|
|
|
|
ip = in1.trim_end().to_string();
|
|
|
|
port = in2.trim_end().to_string();
|
|
|
|
address = format!("{}:{}", ip, port);
|
|
|
|
println!("{}", address);
|
|
|
|
}
|
|
|
|
_ => return
|
|
|
|
}
|
|
|
|
match TcpStream::connect(address)
|
|
|
|
{
|
2023-10-08 01:52:42 +03:00
|
|
|
Ok(mut stream) =>
|
2023-09-16 19:15:30 +03:00
|
|
|
{
|
2023-09-17 07:28:18 +03:00
|
|
|
let start_time = Instant::now();
|
2023-09-16 19:15:30 +03:00
|
|
|
println!("Connected");
|
2023-10-08 01:52:42 +03:00
|
|
|
FileInfo::reading_operations(file_info, &mut stream);
|
2023-09-17 07:28:18 +03:00
|
|
|
let finish_time = Instant::now();
|
|
|
|
println!("Passed: Total -> {:#?}", finish_time.duration_since(start_time));
|
2023-09-16 19:15:30 +03:00
|
|
|
}
|
|
|
|
Err(e) =>
|
|
|
|
{
|
|
|
|
println!("Error: Connection -> {}", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-14 08:29:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-16 19:15:30 +03:00
|
|
|
fn take_string(output:String) -> String
|
|
|
|
{
|
|
|
|
let mut input = String::new();
|
|
|
|
println!("{}", output);
|
2023-10-02 22:04:41 +03:00
|
|
|
io::stdin().read_line(&mut input).expect("Error: Failed to Read from Console");
|
2023-09-16 19:15:30 +03:00
|
|
|
input
|
|
|
|
}
|
|
|
|
fn take_arg() -> String
|
|
|
|
{
|
|
|
|
env::args().last().as_deref().unwrap_or("default").to_string()
|
|
|
|
}
|
|
|
|
|
2023-09-14 08:29:32 +03:00
|
|
|
fn main()
|
|
|
|
{
|
2023-10-02 22:04:41 +03:00
|
|
|
//DONT FORGET
|
|
|
|
//First we should check folder structure and validation then make connection.
|
2023-09-14 08:29:32 +03:00
|
|
|
println!("Hello, world!");
|
2023-09-16 19:15:30 +03:00
|
|
|
|
|
|
|
let mut data = FileInfo
|
|
|
|
{
|
|
|
|
file:None,
|
|
|
|
location:take_arg(),
|
2023-10-08 01:52:42 +03:00
|
|
|
size_current:0 as usize,
|
2023-10-02 22:04:41 +03:00
|
|
|
metadata:None,
|
2023-09-16 19:15:30 +03:00
|
|
|
};
|
|
|
|
match &take_string("Input: Server 's', Client 'c'".to_string())[0..1]
|
|
|
|
{
|
|
|
|
"s" =>
|
|
|
|
{
|
|
|
|
Connection::server
|
|
|
|
(Connection::Server(take_string("Input: Server Stream IP Address".to_string()),
|
|
|
|
take_string("Input: Server Stream Port Address".to_string())),
|
|
|
|
&mut data);
|
|
|
|
},
|
|
|
|
"c" =>
|
|
|
|
{
|
|
|
|
Connection::client
|
|
|
|
(Connection::Client(take_string("Input: Server IP Address to Connect".to_string()),
|
|
|
|
take_string("Input: Server Port Address to Connect".to_string())),
|
|
|
|
&mut data);
|
|
|
|
}
|
|
|
|
input =>
|
|
|
|
{
|
|
|
|
println!("Error: Give Valid Input, You Gave : {}", input);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2023-09-14 08:29:32 +03:00
|
|
|
}
|