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