diff --git a/src/ssh.rs b/src/ssh.rs index 0de3427..45ab175 100644 --- a/src/ssh.rs +++ b/src/ssh.rs @@ -105,6 +105,9 @@ pub struct SshOpts { parse_rules: ParseRule, /// Ssh agent configuration for authentication ssh_agent_identity: Option, + /// do not use any shell command when doing SCP operations + /// to make sure to be compatible with non unix systems + pure_scp: bool, } impl SshOpts { @@ -125,6 +128,7 @@ impl SshOpts { methods: Vec::default(), parse_rules: ParseRule::STRICT, ssh_agent_identity: None, + pure_scp: false, } } @@ -166,6 +170,13 @@ impl SshOpts { self } + /// do not use any shell command when doing SCP operations + /// to make sure to be compatible with non unix systems + pub fn pure_scp(mut self, pure_scp: bool) -> Self { + self.pure_scp = pure_scp; + self + } + /// Set SSH configuration file to read /// /// The supported options are: diff --git a/src/ssh/scp.rs b/src/ssh/scp.rs index b8a4e21..c64a920 100644 --- a/src/ssh/scp.rs +++ b/src/ssh/scp.rs @@ -242,11 +242,13 @@ where "Connection established: {}", banner.as_deref().unwrap_or("") ); - // Get working directory - debug!("Getting working directory..."); - self.wrkdir = session - .cmd("pwd") - .map(|(_rc, output)| PathBuf::from(output.as_str().trim()))?; + if !self.opts.pure_scp { + // Get working directory + debug!("Getting working directory..."); + self.wrkdir = session + .cmd("pwd") + .map(|(_rc, output)| PathBuf::from(output.as_str().trim()))?; + } // Set session self.session = Some(session); info!( @@ -667,9 +669,11 @@ where self.check_connection()?; let path = path_utils::absolutize(self.wrkdir.as_path(), path); debug!("Opening file {} for read", path.display()); - // check if file exists - if !self.exists(path.as_path()).ok().unwrap_or(false) { - return Err(RemoteError::new(RemoteErrorType::NoSuchFileOrDirectory)); + if !self.opts.pure_scp { + // check if file exists + if !self.exists(path.as_path()).ok().unwrap_or(false) { + return Err(RemoteError::new(RemoteErrorType::NoSuchFileOrDirectory)); + } } trace!("blocked channel"); match self.session.as_mut().unwrap().scp_recv(path.as_path()) {