28
28
import java .io .IOException ;
29
29
import java .io .InputStream ;
30
30
import java .io .OutputStream ;
31
+ import java .util .LinkedList ;
31
32
import java .util .List ;
32
33
33
34
/** @see <a href="http://blogs.sun.com/janp/entry/how_the_scp_protocol_works">SCP Protocol</a> */
@@ -39,7 +40,8 @@ enum Arg {
39
40
RECURSIVE ('r' ),
40
41
VERBOSE ('v' ),
41
42
PRESERVE_TIMES ('p' ),
42
- QUIET ('q' );
43
+ QUIET ('q' ),
44
+ LIMIT ('l' );
43
45
44
46
private final char a ;
45
47
@@ -97,10 +99,10 @@ void cleanSlate() {
97
99
exitStatus = -1 ;
98
100
}
99
101
100
- void execSCPWith (List <Arg > args , String path )
102
+ void execSCPWith (List <SCPArgument > args , String path )
101
103
throws SSHException {
102
104
final StringBuilder cmd = new StringBuilder (SCP_COMMAND );
103
- for (Arg arg : args ) {
105
+ for (SCPArgument arg : args ) {
104
106
cmd .append (" " ).append (arg );
105
107
}
106
108
cmd .append (" " );
@@ -186,4 +188,84 @@ TransferListener getTransferListener() {
186
188
return listener ;
187
189
}
188
190
191
+ public static class SCPArgument {
192
+
193
+ private Arg name ;
194
+ private String value ;
195
+
196
+ private SCPArgument (Arg name , String value ) {
197
+ this .name = name ;
198
+ this .value = value ;
199
+ }
200
+
201
+ public static SCPArgument addArgument (Arg name , String value ) {
202
+ return new SCPArgument (name , value );
203
+ }
204
+
205
+ @ Override
206
+ public String toString () {
207
+ String option = name .toString ();
208
+ if (value != null ) {
209
+ option = option + value ;
210
+ }
211
+ return option ;
212
+ }
213
+ }
214
+
215
+ public static class SCPArguments {
216
+
217
+ private static List <SCPArgument > args = null ;
218
+
219
+ private SCPArguments () {
220
+ this .args = new LinkedList <SCPArgument >();
221
+ }
222
+
223
+ private static void addArgument (Arg name , String value , boolean accept ) {
224
+ if (accept ) {
225
+ args .add (SCPArgument .addArgument (name , value ));
226
+ }
227
+ }
228
+
229
+ public static SCPArguments with (Arg name ) {
230
+ return with (name , null , true );
231
+ }
232
+
233
+ public static SCPArguments with (Arg name , String value ) {
234
+ return with (name , value , true );
235
+ }
236
+
237
+ public static SCPArguments with (Arg name , boolean accept ) {
238
+ return with (name , null , accept );
239
+ }
240
+
241
+ public static SCPArguments with (Arg name , String value , boolean accept ) {
242
+ SCPArguments scpArguments = new SCPArguments ();
243
+ addArgument (name , value , accept );
244
+ return scpArguments ;
245
+ }
246
+
247
+ public SCPArguments and (Arg name ) {
248
+ addArgument (name , null , true );
249
+ return this ;
250
+ }
251
+
252
+ public SCPArguments and (Arg name , String value ) {
253
+ addArgument (name , value , true );
254
+ return this ;
255
+ }
256
+
257
+ public SCPArguments and (Arg name , boolean accept ) {
258
+ addArgument (name , null , accept );
259
+ return this ;
260
+ }
261
+
262
+ public SCPArguments and (Arg name , String value , boolean accept ) {
263
+ addArgument (name , value , accept );
264
+ return this ;
265
+ }
266
+
267
+ public List <SCPArgument > arguments () {
268
+ return args ;
269
+ }
270
+ }
189
271
}
0 commit comments