mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
Changed Callback for file transfer; mkdir using path instead of String
This commit is contained in:
@@ -32,7 +32,7 @@ use crate::fs::FsEntry;
|
|||||||
pub mod sftp_transfer;
|
pub mod sftp_transfer;
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
type ProgressCallback = fn(bytes_written: usize, size: usize);
|
pub type ProgressCallback = dyn Fn(usize, usize);
|
||||||
|
|
||||||
/// ## FileTransferProtocol
|
/// ## FileTransferProtocol
|
||||||
///
|
///
|
||||||
@@ -125,7 +125,7 @@ pub trait FileTransfer {
|
|||||||
/// ### mkdir
|
/// ### mkdir
|
||||||
///
|
///
|
||||||
/// Make directory
|
/// Make directory
|
||||||
fn mkdir(&self, dir: String) -> Result<(), FileTransferError>;
|
fn mkdir(&self, dir: &Path) -> Result<(), FileTransferError>;
|
||||||
|
|
||||||
/// ### remove
|
/// ### remove
|
||||||
///
|
///
|
||||||
@@ -142,11 +142,11 @@ pub trait FileTransfer {
|
|||||||
/// Send file to remote
|
/// Send file to remote
|
||||||
/// File name is referred to the name of the file as it will be saved
|
/// File name is referred to the name of the file as it will be saved
|
||||||
/// Data contains the file data
|
/// Data contains the file data
|
||||||
fn send_file(&self, file_name: &Path, file: &mut File, prog_cb: Option<ProgressCallback>) -> Result<(), FileTransferError>;
|
fn send_file(&self, file_name: &Path, file: &mut File, prog_cb: Option<Box<ProgressCallback>>) -> Result<(), FileTransferError>;
|
||||||
|
|
||||||
/// ### recv_file
|
/// ### recv_file
|
||||||
///
|
///
|
||||||
/// Receive file from remote with provided name
|
/// Receive file from remote with provided name
|
||||||
fn recv_file(&self, file_name: &Path, dest_file: &mut File, prog_cb: Option<ProgressCallback>) -> Result<(), FileTransferError>;
|
fn recv_file(&self, file_name: &Path, dest_file: &mut File, prog_cb: Option<Box<ProgressCallback>>) -> Result<(), FileTransferError>;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -313,7 +313,7 @@ impl FileTransfer for SftpFileTransfer {
|
|||||||
/// ### mkdir
|
/// ### mkdir
|
||||||
///
|
///
|
||||||
/// Make directory
|
/// Make directory
|
||||||
fn mkdir(&self, dir: String) -> Result<(), FileTransferError> {
|
fn mkdir(&self, dir: &Path) -> Result<(), FileTransferError> {
|
||||||
match self.sftp.as_ref() {
|
match self.sftp.as_ref() {
|
||||||
Some(sftp) => {
|
Some(sftp) => {
|
||||||
// Make directory
|
// Make directory
|
||||||
@@ -399,7 +399,7 @@ impl FileTransfer for SftpFileTransfer {
|
|||||||
&self,
|
&self,
|
||||||
file_name: &Path,
|
file_name: &Path,
|
||||||
file: &mut File,
|
file: &mut File,
|
||||||
prog_cb: Option<ProgressCallback>,
|
prog_cb: Option<Box<ProgressCallback>>,
|
||||||
) -> Result<(), FileTransferError> {
|
) -> Result<(), FileTransferError> {
|
||||||
match self.sftp.as_ref() {
|
match self.sftp.as_ref() {
|
||||||
None => Err(FileTransferError::UninitializedSession),
|
None => Err(FileTransferError::UninitializedSession),
|
||||||
@@ -429,7 +429,7 @@ impl FileTransfer for SftpFileTransfer {
|
|||||||
return Err(FileTransferError::IoErr(err));
|
return Err(FileTransferError::IoErr(err));
|
||||||
}
|
}
|
||||||
// Call callback
|
// Call callback
|
||||||
if let Some(cb) = prog_cb {
|
if let Some(ref cb) = prog_cb {
|
||||||
cb(total_bytes_written, file_size);
|
cb(total_bytes_written, file_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -452,7 +452,7 @@ impl FileTransfer for SftpFileTransfer {
|
|||||||
&self,
|
&self,
|
||||||
file_name: &Path,
|
file_name: &Path,
|
||||||
dest_file: &mut File,
|
dest_file: &mut File,
|
||||||
prog_cb: Option<ProgressCallback>,
|
prog_cb: Option<Box<ProgressCallback>>,
|
||||||
) -> Result<(), FileTransferError> {
|
) -> Result<(), FileTransferError> {
|
||||||
match self.sftp.as_ref() {
|
match self.sftp.as_ref() {
|
||||||
None => Err(FileTransferError::UninitializedSession),
|
None => Err(FileTransferError::UninitializedSession),
|
||||||
@@ -487,7 +487,7 @@ impl FileTransfer for SftpFileTransfer {
|
|||||||
return Err(FileTransferError::IoErr(err));
|
return Err(FileTransferError::IoErr(err));
|
||||||
}
|
}
|
||||||
// Call callback
|
// Call callback
|
||||||
if let Some(cb) = prog_cb {
|
if let Some(ref cb) = prog_cb {
|
||||||
cb(total_bytes_written, file_size);
|
cb(total_bytes_written, file_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -699,7 +699,7 @@ mod tests {
|
|||||||
.recv_file(
|
.recv_file(
|
||||||
PathBuf::from("readme.txt").as_path(),
|
PathBuf::from("readme.txt").as_path(),
|
||||||
&mut dst_file_hnd,
|
&mut dst_file_hnd,
|
||||||
Some(progress_callback)
|
Some(Box::new(progress_callback))
|
||||||
)
|
)
|
||||||
.is_ok());
|
.is_ok());
|
||||||
// Disconnect
|
// Disconnect
|
||||||
@@ -733,7 +733,7 @@ mod tests {
|
|||||||
.recv_file(
|
.recv_file(
|
||||||
PathBuf::from("omar.txt").as_path(),
|
PathBuf::from("omar.txt").as_path(),
|
||||||
&mut dst_file_hnd,
|
&mut dst_file_hnd,
|
||||||
Some(progress_callback)
|
Some(Box::new(progress_callback))
|
||||||
)
|
)
|
||||||
.is_err());
|
.is_err());
|
||||||
// Disconnect
|
// Disconnect
|
||||||
@@ -770,7 +770,7 @@ mod tests {
|
|||||||
.recv_file(
|
.recv_file(
|
||||||
PathBuf::from("readme.txt").as_path(),
|
PathBuf::from("readme.txt").as_path(),
|
||||||
&mut dst_file_hnd,
|
&mut dst_file_hnd,
|
||||||
Some(progress_callback)
|
Some(Box::new(progress_callback))
|
||||||
)
|
)
|
||||||
.is_err());
|
.is_err());
|
||||||
// Disconnect
|
// Disconnect
|
||||||
|
|||||||
Reference in New Issue
Block a user