@@ -166,6 +166,63 @@ impl Session {
166166 )
167167 }
168168
169+ /// Constructs a new [`Command`] for launching subsystem `program` on the remote
170+ /// host.
171+ ///
172+ /// Unlike [`command`](Session::command), this method does not shell-escape `program`, so it may be evaluated in
173+ /// unforeseen ways by the remote shell.
174+ ///
175+ /// The returned `Command` is a builder, with the following default configuration:
176+ ///
177+ /// * No arguments to the program
178+ /// * Empty stdin and dsicard stdout/stderr for `spawn` or `status`, but create output pipes for
179+ /// `output`
180+ ///
181+ /// Builder methods are provided to change these defaults and otherwise configure the process.
182+ ///
183+ /// ## Sftp subsystem
184+ ///
185+ /// To use the sftp subsystem, you'll want to use [`openssh-sftp-client`],
186+ /// then use the following code to construct a sftp instance:
187+ ///
188+ /// [`openssh-sftp-client`]: https://crates.io/crates/openssh-sftp-client
189+ ///
190+ /// ```rust,no_run
191+ /// # use std::error::Error;
192+ /// # #[cfg(feature = "native-mux")]
193+ /// # #[tokio::main]
194+ /// # async fn main() -> Result<(), Box<dyn Error>> {
195+ ///
196+ /// use openssh::{Session, KnownHosts, Stdio};
197+ /// use openssh_sftp_client::highlevel::Sftp;
198+ ///
199+ /// let session = Session::connect_mux("me@ssh.example.com", KnownHosts::Strict).await?;
200+ ///
201+ /// let mut child = session
202+ /// .subsystem("sftp")
203+ /// .stdin(Stdio::piped())
204+ /// .stdout(Stdio::piped())
205+ /// .spawn()
206+ /// .await?;
207+ ///
208+ /// Sftp::new(
209+ /// child.stdin().take().unwrap(),
210+ /// child.stdout().take().unwrap(),
211+ /// Default::default(),
212+ /// )
213+ /// .await?
214+ /// .close()
215+ /// .await?;
216+ ///
217+ /// # Ok(()) }
218+ /// ```
219+ pub fn subsystem < S : AsRef < OsStr > > ( & self , program : S ) -> Command < ' _ > {
220+ Command :: new (
221+ self ,
222+ delegate ! ( & self . 0 , imp, { imp. subsystem( program) . into( ) } ) ,
223+ )
224+ }
225+
169226 /// Constructs a new [`Command`] that runs the provided shell command on the remote host.
170227 ///
171228 /// The provided command is passed as a single, escaped argument to `sh -c`, and from that
0 commit comments