@@ -49,6 +49,7 @@ pub struct SessionBuilder {
49
49
known_hosts_check : KnownHosts ,
50
50
control_dir : Option < PathBuf > ,
51
51
config_file : Option < PathBuf > ,
52
+ compression : Option < bool > ,
52
53
}
53
54
54
55
impl Default for SessionBuilder {
@@ -62,6 +63,7 @@ impl Default for SessionBuilder {
62
63
known_hosts_check : KnownHosts :: Add ,
63
64
control_dir : None ,
64
65
config_file : None ,
66
+ compression : None ,
65
67
}
66
68
}
67
69
}
@@ -137,6 +139,21 @@ impl SessionBuilder {
137
139
self
138
140
}
139
141
142
+ /// Enable or disable compression (including stdin, stdout, stderr, data
143
+ /// for forwarded TCP and unix-domain connections, sftp and scp
144
+ /// connections).
145
+ ///
146
+ /// Note that the ssh server can forcibly disable the compression.
147
+ ///
148
+ /// By default, ssh uses configure value set in `~/.ssh/config`.
149
+ ///
150
+ /// If `~/.ssh/config` does not enable compression, then it is disabled
151
+ /// by default.
152
+ pub fn compression ( & mut self , compression : bool ) -> & mut Self {
153
+ self . compression = Some ( compression) ;
154
+ self
155
+ }
156
+
140
157
/// Connect to the host at the given `host` over SSH using process impl, which will
141
158
/// spawn a new ssh process for each `Child` created.
142
159
///
@@ -277,6 +294,12 @@ impl SessionBuilder {
277
294
init. arg ( "-F" ) . arg ( config_file) ;
278
295
}
279
296
297
+ if let Some ( compression) = self . compression {
298
+ let arg = if compression { "yes" } else { "no" } ;
299
+
300
+ init. arg ( "-o" ) . arg ( format ! ( "Compression={}" , arg) ) ;
301
+ }
302
+
280
303
init. arg ( destination) ;
281
304
282
305
// we spawn and immediately wait, because the process is supposed to fork.
0 commit comments