1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.vfs2.provider.ftp;
18
19 import java.net.Proxy;
20 import java.nio.charset.Charset;
21 import java.time.Duration;
22 import java.util.ArrayList;
23 import java.util.Arrays;
24 import java.util.List;
25
26 import org.apache.commons.lang3.Range;
27 import org.apache.commons.net.ftp.FTPReply;
28 import org.apache.commons.net.ftp.parser.FTPFileEntryParserFactory;
29 import org.apache.commons.vfs2.FileContent;
30 import org.apache.commons.vfs2.FileSystem;
31 import org.apache.commons.vfs2.FileSystemConfigBuilder;
32 import org.apache.commons.vfs2.FileSystemOptions;
33
34
35
36
37 public class FtpFileSystemConfigBuilder extends FileSystemConfigBuilder {
38
39 private static final String PREFIX = FtpFileSystemConfigBuilder.class.getName();
40
41 private static final FtpFileSystemConfigBuilder BUILDER = new FtpFileSystemConfigBuilder();
42
43 private static final String AUTODETECT_UTF8 = PREFIX + ".AUTODETECT_UTF8";
44 private static final String CONNECT_TIMEOUT = PREFIX + ".CONNECT_TIMEOUT";
45 private static final String DATA_TIMEOUT = PREFIX + ".DATA_TIMEOUT";
46 private static final String DEFAULT_DATE_FORMAT = PREFIX + ".DEFAULT_DATE_FORMAT";
47 private static final String ENCODING = PREFIX + ".ENCODING";
48 private static final String FACTORY_KEY = FTPFileEntryParserFactory.class.getName() + ".KEY";
49 private static final String FILE_TYPE = PREFIX + ".FILE_TYPE";
50 private static final String PASSIVE_MODE = PREFIX + ".PASSIVE";
51 private static final String ACTIVE_PORT_RANGE = PREFIX + ".ACTIVE_PORT_RANGE";
52 private static final String PROXY = PREFIX + ".PROXY";
53 private static final String RECENT_DATE_FORMAT = PREFIX + ".RECENT_DATE_FORMAT";
54 private static final String REMOTE_VERIFICATION = PREFIX + ".REMOTE_VERIFICATION";
55 private static final String SERVER_LANGUAGE_CODE = PREFIX + ".SERVER_LANGUAGE_CODE";
56 private static final String SERVER_TIME_ZONE_ID = PREFIX + ".SERVER_TIME_ZONE_ID";
57 private static final String SHORT_MONTH_NAMES = PREFIX + ".SHORT_MONTH_NAMES";
58 private static final String SO_TIMEOUT = PREFIX + ".SO_TIMEOUT";
59 private static final String CONTROL_KEEP_ALIVE_TIMEOUT = PREFIX + ".CONTROL_KEEP_ALIVE_TIMEOUT";
60 private static final String CONTROL_KEEP_ALIVE_REPLY_TIMEOUT = PREFIX + ".CONTROL_KEEP_ALIVE_REPLY_TIMEOUT";
61 private static final String USER_DIR_IS_ROOT = PREFIX + ".USER_DIR_IS_ROOT";
62 private static final String TRANSFER_ABORTED_OK_REPLY_CODES = PREFIX + ".TRANSFER_ABORTED_OK_REPLY_CODES";
63 private static final String MDTM_LAST_MODIFED_TIME = PREFIX + ".MDTM_LAST_MODIFED_TIME";
64
65
66
67
68
69
70 public static FtpFileSystemConfigBuilder getInstance() {
71 return BUILDER;
72 }
73
74
75
76
77
78
79
80
81 public static List<Integer> getSaneTransferAbortedOkReplyCodes() {
82
83 return new ArrayList<>(Arrays.asList(FTPReply.TRANSFER_ABORTED, FTPReply.FILE_UNAVAILABLE));
84 }
85
86 private FtpFileSystemConfigBuilder() {
87 super("ftp.");
88 }
89
90
91
92
93
94
95
96 protected FtpFileSystemConfigBuilder(final String prefix) {
97 super(prefix);
98 }
99
100
101
102
103
104
105
106
107 public Range<Integer> getActivePortRange(final FileSystemOptions options) {
108 return getParam(options, ACTIVE_PORT_RANGE);
109 }
110
111
112
113
114
115
116
117
118 public Boolean getAutodetectUtf8(final FileSystemOptions options) {
119 return getBoolean(options, AUTODETECT_UTF8);
120 }
121
122 @Override
123 protected Class<? extends FileSystem> getConfigClass() {
124 return FtpFileSystem.class;
125 }
126
127
128
129
130
131
132
133
134
135 @Deprecated
136 public Integer getConnectTimeout(final FileSystemOptions options) {
137 return getDurationInteger(options, CONNECT_TIMEOUT);
138 }
139
140
141
142
143
144
145
146
147 public Duration getConnectTimeoutDuration(final FileSystemOptions options) {
148 return getDuration(options, CONNECT_TIMEOUT);
149 }
150
151
152
153
154
155
156
157
158
159 @Deprecated
160 public String getControlEncoding(final FileSystemOptions options) {
161 return getString(options, ENCODING);
162 }
163
164
165
166
167
168
169
170
171 public Charset getControlEncodingCharset(final FileSystemOptions options) {
172 return getCharset(options, ENCODING);
173 }
174
175
176
177
178
179
180
181
182 public Duration getControlKeepAliveReplyTimeout(final FileSystemOptions options) {
183 return getDuration(options, CONTROL_KEEP_ALIVE_REPLY_TIMEOUT);
184 }
185
186
187
188
189
190
191
192
193 public Duration getControlKeepAliveTimeout(final FileSystemOptions options) {
194 return getDuration(options, CONTROL_KEEP_ALIVE_TIMEOUT);
195 }
196
197
198
199
200
201
202
203
204
205 @Deprecated
206 public Integer getDataTimeout(final FileSystemOptions options) {
207 return getDurationInteger(options, DATA_TIMEOUT);
208 }
209
210
211
212
213
214
215
216
217
218 public Duration getDataTimeoutDuration(final FileSystemOptions options) {
219 return getDuration(options, DATA_TIMEOUT);
220 }
221
222
223
224
225
226
227
228
229 public String getDefaultDateFormat(final FileSystemOptions options) {
230 return getString(options, DEFAULT_DATE_FORMAT);
231 }
232
233
234
235
236
237
238
239
240 public String getEntryParser(final FileSystemOptions options) {
241 return getString(options, FACTORY_KEY);
242 }
243
244
245
246
247
248
249
250
251 public FTPFileEntryParserFactory getEntryParserFactory(final FileSystemOptions options) {
252 return getParam(options, FTPFileEntryParserFactory.class.getName());
253 }
254
255
256
257
258
259
260
261
262 public FtpFileType getFileType(final FileSystemOptions options) {
263 return getEnum(FtpFileType.class, options, FILE_TYPE);
264 }
265
266
267
268
269
270
271
272
273 public Boolean getMdtmLastModifiedTime(final FileSystemOptions options) {
274 return getBoolean(options, MDTM_LAST_MODIFED_TIME);
275 }
276
277
278
279
280
281
282
283
284 public Boolean getPassiveMode(final FileSystemOptions options) {
285 return getBoolean(options, PASSIVE_MODE);
286 }
287
288
289
290
291
292
293
294
295 public Proxy getProxy(final FileSystemOptions options) {
296 return getParam(options, PROXY);
297 }
298
299
300
301
302
303
304
305 public String getRecentDateFormat(final FileSystemOptions options) {
306 return getString(options, RECENT_DATE_FORMAT);
307 }
308
309
310
311
312
313
314
315 public Boolean getRemoteVerification(final FileSystemOptions options) {
316 return getBoolean(options, REMOTE_VERIFICATION);
317 }
318
319
320
321
322
323
324
325
326 public String getServerLanguageCode(final FileSystemOptions options) {
327 return getString(options, SERVER_LANGUAGE_CODE);
328 }
329
330
331
332
333
334
335
336 public String getServerTimeZoneId(final FileSystemOptions options) {
337 return getString(options, SERVER_TIME_ZONE_ID);
338 }
339
340
341
342
343
344
345
346 public String[] getShortMonthNames(final FileSystemOptions options) {
347 return getParam(options, SHORT_MONTH_NAMES);
348 }
349
350
351
352
353
354
355
356
357
358
359 @Deprecated
360 public Integer getSoTimeout(final FileSystemOptions options) {
361 return getDurationInteger(options, SO_TIMEOUT);
362 }
363
364
365
366
367
368
369
370
371
372 public Duration getSoTimeoutDuration(final FileSystemOptions options) {
373 return getDuration(options, SO_TIMEOUT);
374 }
375
376
377
378
379
380
381
382
383 public List<Integer> getTransferAbortedOkReplyCodes(final FileSystemOptions options) {
384 return getParam(options, TRANSFER_ABORTED_OK_REPLY_CODES);
385 }
386
387
388
389
390
391
392
393
394
395
396 public Boolean getUserDirIsRoot(final FileSystemOptions options) {
397 return getBoolean(options, USER_DIR_IS_ROOT, Boolean.TRUE);
398 }
399
400
401
402
403
404
405
406
407 public void setActivePortRange(final FileSystemOptions options, final Range<Integer> portRange) {
408 setParam(options, ACTIVE_PORT_RANGE, portRange);
409 }
410
411
412
413
414
415
416
417
418 public void setAutodetectUtf8(final FileSystemOptions options, final Boolean autodetectUTF8) {
419 setParam(options, AUTODETECT_UTF8, autodetectUTF8);
420 }
421
422
423
424
425
426
427
428
429
430
431
432 public void setConnectTimeout(final FileSystemOptions options, final Duration duration) {
433 setParam(options, CONNECT_TIMEOUT, duration);
434 }
435
436
437
438
439
440
441
442
443
444
445
446
447 @Deprecated
448 public void setConnectTimeout(final FileSystemOptions options, final Integer duration) {
449 setConnectTimeout(options, Duration.ofMillis(duration));
450 }
451
452
453
454
455
456
457
458
459 public void setControlEncoding(final FileSystemOptions options, final Charset encoding) {
460 setParam(options, ENCODING, encoding);
461 }
462
463
464
465
466
467
468
469
470
471 @Deprecated
472 public void setControlEncoding(final FileSystemOptions options, final String encoding) {
473 setParam(options, ENCODING, encoding);
474 }
475
476
477
478
479
480
481
482
483 public void setControlKeepAliveReplyTimeout(final FileSystemOptions options, final Duration duration) {
484 setParam(options, CONTROL_KEEP_ALIVE_REPLY_TIMEOUT, duration);
485 }
486
487
488
489
490
491
492
493
494
495
496
497 public void setControlKeepAliveTimeout(final FileSystemOptions options, final Duration duration) {
498 setParam(options, CONTROL_KEEP_ALIVE_TIMEOUT, duration);
499 }
500
501
502
503
504
505
506
507
508
509
510
511 public void setDataTimeout(final FileSystemOptions options, final Duration duration) {
512 setParam(options, DATA_TIMEOUT, duration);
513 }
514
515
516
517
518
519
520
521
522
523
524
525 @Deprecated
526 public void setDataTimeout(final FileSystemOptions options, final Integer duration) {
527 setDataTimeout(options, Duration.ofMillis(duration));
528 }
529
530
531
532
533
534
535
536
537 public void setDefaultDateFormat(final FileSystemOptions options, final String defaultDateFormat) {
538 setParam(options, DEFAULT_DATE_FORMAT, defaultDateFormat);
539 }
540
541
542
543
544
545
546
547
548
549
550
551 public void setEntryParser(final FileSystemOptions options, final String key) {
552 setParam(options, FACTORY_KEY, key);
553 }
554
555
556
557
558
559
560
561 public void setEntryParserFactory(final FileSystemOptions options, final FTPFileEntryParserFactory factory) {
562 setParam(options, FTPFileEntryParserFactory.class.getName(), factory);
563 }
564
565
566
567
568
569
570
571
572 public void setFileType(final FileSystemOptions options, final FtpFileType ftpFileType) {
573 setParam(options, FILE_TYPE, ftpFileType);
574 }
575
576
577
578
579
580
581
582
583 public void setMdtmLastModifiedTime(final FileSystemOptions options, final boolean mdtm) {
584 setParam(options, MDTM_LAST_MODIFED_TIME, toBooleanObject(mdtm));
585 }
586
587
588
589
590
591
592
593 public void setPassiveMode(final FileSystemOptions options, final boolean passiveMode) {
594 setParam(options, PASSIVE_MODE, toBooleanObject(passiveMode));
595 }
596
597
598
599
600
601
602
603
604
605
606
607 public void setProxy(final FileSystemOptions options, final Proxy proxy) {
608 setParam(options, PROXY, proxy);
609 }
610
611
612
613
614
615
616
617 public void setRecentDateFormat(final FileSystemOptions options, final String recentDateFormat) {
618 setParam(options, RECENT_DATE_FORMAT, recentDateFormat);
619 }
620
621
622
623
624
625
626
627 public void setRemoteVerification(final FileSystemOptions options, final boolean remoteVerification) {
628 setParam(options, REMOTE_VERIFICATION, remoteVerification);
629 }
630
631
632
633
634
635
636
637
638 public void setServerLanguageCode(final FileSystemOptions options, final String serverLanguageCode) {
639 setParam(options, SERVER_LANGUAGE_CODE, serverLanguageCode);
640 }
641
642
643
644
645
646
647
648 public void setServerTimeZoneId(final FileSystemOptions options, final String serverTimeZoneId) {
649 setParam(options, SERVER_TIME_ZONE_ID, serverTimeZoneId);
650 }
651
652
653
654
655
656
657
658 public void setShortMonthNames(final FileSystemOptions options, final String[] shortMonthNames) {
659 String[] clone = null;
660 if (shortMonthNames != null) {
661 clone = Arrays.copyOf(shortMonthNames, shortMonthNames.length);
662 }
663
664 setParam(options, SHORT_MONTH_NAMES, clone);
665 }
666
667
668
669
670
671
672
673
674
675
676
677 public void setSoTimeout(final FileSystemOptions options, final Duration timeout) {
678 setParam(options, SO_TIMEOUT, timeout);
679 }
680
681
682
683
684
685
686
687
688
689
690
691
692 @Deprecated
693 public void setSoTimeout(final FileSystemOptions options, final Integer timeout) {
694 setSoTimeout(options, Duration.ofMillis(timeout));
695 }
696
697
698
699
700
701
702
703
704
705
706
707
708 public void setTransferAbortedOkReplyCodes(final FileSystemOptions options, final List<Integer> replyCodes) {
709 setParam(options, TRANSFER_ABORTED_OK_REPLY_CODES, replyCodes);
710 }
711
712
713
714
715
716
717
718 public void setUserDirIsRoot(final FileSystemOptions options, final boolean userDirIsRoot) {
719 setParam(options, USER_DIR_IS_ROOT, toBooleanObject(userDirIsRoot));
720 }
721 }