Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
jpx40 committed Feb 25, 2024
1 parent 6f558ff commit 75f8cd0
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 3 deletions.
61 changes: 61 additions & 0 deletions central/rsrem/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions central/rsrem/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ edition = "2021"
[dependencies]
crossbeam = "0.8.4"
crossbeam-channel = "0.5.11"
crossbeam-epoch = "0.9.18"
crossbeam-queue = "0.3.11"
curl = "0.4.46"
http = "1.0.0"
log = "0.4.20"
openssl = { version = "0.10.64", features = ["v110"] }
regex = "1.10.3"
Expand All @@ -15,4 +18,5 @@ serde = { version = "1.0.197", features = ["derive"] }
serde_json = "1.0.114"
smol = "2.0.0"
ssh2 = { version = "0.9.4", features = ["vendored-openssl"] }
time = "0.3.34"
toml = "0.8.10"
46 changes: 43 additions & 3 deletions central/rsrem/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ssh2::Session;
use ssh2::{Channel, Session, Sftp, Stream};
use std::clone;
use std::fs::File;
use std::io::prelude::*;
Expand Down Expand Up @@ -72,7 +72,7 @@ fn main() {

let mut remote_file = RemoteFile::new(path.to_str().unwrap().to_string());
// file_upload(&mut session, path, size, &buffer, times);
remote_file.file_upload(&mut session, &buffer);
remote_file.send(&mut session);

let test = String::from_utf8(buffer).unwrap();
println!("String: {}\nSize: {}", test, size);
Expand Down Expand Up @@ -119,7 +119,47 @@ impl RemoteFile {
}
}

fn file_upload(&mut self, session: &mut Session, buf: &[u8]) {
fn set_mode(&mut self, mode: i32) {
self.mode = mode;
}

fn add_buf(&mut self, buf: Vec<u8>) {
self.buf = Some(buf);
}
fn set_times(&mut self, times: Option<(u64, u64)>) {
self.times = times;
}
fn set_size(&mut self, size: u64) {
self.size = size;
}
fn set_path(&mut self, path: String) {
self.path = path;
}

fn send(self, session: &mut Session) {
let mut buffer: Vec<u8>;
match self.buf {
Some(b) => {
buffer = b;
}
None => {
buffer = Vec::new();

let _ = File::open(&self.path).unwrap().read_to_end(&mut buffer);
}
};
let mut remote_file = session
.scp_send(Path::new(&self.path), self.mode, self.size, self.times)
.unwrap();

remote_file.write_all(&buffer).unwrap();
// Close the channel and wait for the whole content to be transferred
remote_file.send_eof().unwrap();
remote_file.wait_eof().unwrap();
remote_file.close().unwrap();
remote_file.wait_close().unwrap();
}
fn send_with_buf(&mut self, session: &mut Session, buf: &[u8]) {
let mut remote_file = session
.scp_send(Path::new(&self.path), self.mode, self.size, self.times)
.unwrap();
Expand Down

0 comments on commit 75f8cd0

Please sign in to comment.