@@ -166,6 +166,61 @@ impl Session {
166
166
)
167
167
}
168
168
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 sftp subsystem, it is recommended to enable feature `openssh-sftp-client`,
186
+ /// then use the following code to construct a sftp instance:
187
+ ///
188
+ /// ```rust,no_run
189
+ /// # use std::error::Error;
190
+ /// # #[cfg(feature = "native-mux")]
191
+ /// # #[tokio::main]
192
+ /// # async fn main() -> Result<(), Box<dyn Error>> {
193
+ ///
194
+ /// use openssh::{Session, KnownHosts, Stdio};
195
+ /// use openssh_sftp_client::highlevel::Sftp;
196
+ ///
197
+ /// let session = Session::connect_mux("me@ssh.example.com", KnownHosts::Strict).await?;
198
+ ///
199
+ /// let mut child = session
200
+ /// .subsystem("sftp")
201
+ /// .stdin(Stdio::piped())
202
+ /// .stdout(Stdio::piped())
203
+ /// .spawn()
204
+ /// .await?;
205
+ ///
206
+ /// Sftp::new(
207
+ /// child.stdin().take().unwrap(),
208
+ /// child.stdout().take().unwrap(),
209
+ /// Default::default(),
210
+ /// )
211
+ /// .await?
212
+ /// .close()
213
+ /// .await?;
214
+ ///
215
+ /// # Ok(()) }
216
+ /// ```
217
+ pub fn subsystem < S : AsRef < OsStr > > ( & self , program : S ) -> Command < ' _ > {
218
+ Command :: new (
219
+ self ,
220
+ delegate ! ( & self . 0 , imp, { imp. subsystem( program) . into( ) } ) ,
221
+ )
222
+ }
223
+
169
224
/// Constructs a new [`Command`] that runs the provided shell command on the remote host.
170
225
///
171
226
/// The provided command is passed as a single, escaped argument to `sh -c`, and from that
0 commit comments