Class FTPClientConfig
- java.lang.Object
-
- org.apache.commons.net.ftp.FTPClientConfig
-
public class FTPClientConfig extends java.lang.ObjectThis class implements an alternate means of configuring the
FTPClientobject and also subordinate objects which it uses. Any class implementing theConfigurableinterface can be configured by this object.In particular this class was designed primarily to support configuration of FTP servers which express file timestamps in formats and languages other than those for the US locale, which although it is the most common is not universal. Unfortunately, nothing in the FTP spec allows this to be determined in an automated way, so manual configuration such as this is necessary.
This functionality was designed to allow existing clients to work exactly as before without requiring use of this component. This component should only need to be explicitly invoked by the user of this package for problem cases that previous implementations could not solve.
Examples of use of FTPClientConfig
Use cases: You are trying to access a server that- lists files with timestamps that use month names in languages other than English
- lists files with timestamps that use date formats other
than the American English "standard"
MM dd yyyy - is in different timezone and you need accurate timestamps for dependency checking as in Ant
Unpaged (whole list) access on a UNIX server that uses French month names but uses the "standard"
MMM d yyyydate formattingFTPClient f=FTPClient(); FTPClientConfig conf = new FTPClientConfig(FTPClientConfig.SYST_UNIX); conf.setServerLanguageCode("fr"); f.configure(conf); f.connect(server); f.login(username, password); FTPFile[] files = listFiles(directory);Paged access on a UNIX server that uses Danish month names and "European" date formatting in Denmark's time zone, when you are in some other time zone.
FTPClient f=FTPClient(); FTPClientConfig conf = new FTPClientConfig(FTPClientConfig.SYST_UNIX); conf.setServerLanguageCode("da"); conf.setDefaultDateFormat("d MMM yyyy"); conf.setRecentDateFormat("d MMM HH:mm"); conf.setTimeZoneId("Europe/Copenhagen"); f.configure(conf); f.connect(server); f.login(username, password); FTPListParseEngine engine = f.initiateListParsing("com.whatever.YourOwnParser", directory); while (engine.hasNext()) { FTPFile[] files = engine.getNext(25); // "page size" you want //do whatever you want with these files, display them, etc. //expensive FTPFile objects not created until needed. }Unpaged (whole list) access on a VMS server that uses month names in a language not
supportedby the system. but uses the "standard"MMM d yyyydate formattingFTPClient f=FTPClient(); FTPClientConfig conf = new FTPClientConfig(FTPClientConfig.SYST_VMS); conf.setShortMonthNames( "jan|feb|mar|apr|maí|jún|júl|ágú|sep|okt|nóv|des"); f.configure(conf); f.connect(server); f.login(username, password); FTPFile[] files = listFiles(directory);Unpaged (whole list) access on a Windows-NT server in a different time zone. (Note, since the NT Format uses numeric date formatting, language issues are irrelevant here).
FTPClient f=FTPClient(); FTPClientConfig conf = new FTPClientConfig(FTPClientConfig.SYST_NT); conf.setTimeZoneId("America/Denver"); f.configure(conf); f.connect(server); f.login(username, password); FTPFile[] files = listFiles(directory);Unpaged (whole list) access on a Windows-NT server in a different time zone but which has been configured to use a unix-style listing format.FTPClient f=FTPClient(); FTPClientConfig conf = new FTPClientConfig(FTPClientConfig.SYST_UNIX); conf.setTimeZoneId("America/Denver"); f.configure(conf); f.connect(server); f.login(username, password); FTPFile[] files = listFiles(directory);- Since:
- 1.4
- See Also:
Configurable,FTPClient,FTPTimestampParserImpl.configure(FTPClientConfig),ConfigurableFTPFileEntryParserImpl
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringSYST_MVSIdentifier by which an MVS-based ftp server is known throughout the commons-net ftp system.static java.lang.StringSYST_NTIdentifier by which a WindowsNT-based ftp server is known throughout the commons-net ftp system.static java.lang.StringSYST_OS2Identifier by which an OS/2-based ftp server is known throughout the commons-net ftp system.static java.lang.StringSYST_OS400Identifier by which an OS/400-based ftp server is known throughout the commons-net ftp system.static java.lang.StringSYST_UNIXIdentifier by which a unix-based ftp server is known throughout the commons-net ftp system.static java.lang.StringSYST_VMSIdentifier by which a vms-based ftp server is known throughout the commons-net ftp system.
-
Constructor Summary
Constructors Constructor Description FTPClientConfig()Convenience constructor mainly for use in testing.FTPClientConfig(java.lang.String systemKey)The main constructor for an FTPClientConfig objectFTPClientConfig(java.lang.String systemKey, java.lang.String defaultDateFormatStr, java.lang.String recentDateFormatStr, java.lang.String serverLanguageCode, java.lang.String shortMonthNames, java.lang.String serverTimeZoneId)Constructor which allows setting of all member fields
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.text.DateFormatSymbolsgetDateFormatSymbols(java.lang.String shortmonths)Returns a DateFormatSymbols object configured with short month names as in the supplied stringjava.lang.StringgetDefaultDateFormatStr()getter for thedefaultDateFormatStrproperty.java.lang.StringgetRecentDateFormatStr()getter for therecentDateFormatStrproperty.java.lang.StringgetServerLanguageCode()getter for theserverLanguageCodeproperty.java.lang.StringgetServerSystemKey()Getter for the serverSystemKey property.java.lang.StringgetServerTimeZoneId()getter for theserverTimeZoneIdproperty.java.lang.StringgetShortMonthNames()getter for theshortMonthNamesproperty.static java.util.CollectiongetSupportedLanguageCodes()Returns a Collection of all the language codes currently supported by this class.static java.text.DateFormatSymbolslookupDateFormatSymbols(java.lang.String languageCode)Looks up the supplied language code in the internally maintained table of language codes.voidsetDefaultDateFormatStr(java.lang.String defaultDateFormatStr)setter for the defaultDateFormatStr property.voidsetRecentDateFormatStr(java.lang.String recentDateFormatStr)setter for the recentDateFormatStr property.voidsetServerLanguageCode(java.lang.String serverLanguageCode)setter for the serverLanguageCode property.voidsetServerTimeZoneId(java.lang.String serverTimeZoneId)setter for the serverTimeZoneId property.voidsetShortMonthNames(java.lang.String shortMonthNames)setter for the shortMonthNames property.
-
-
-
Field Detail
-
SYST_UNIX
public static final java.lang.String SYST_UNIX
Identifier by which a unix-based ftp server is known throughout the commons-net ftp system.- See Also:
- Constant Field Values
-
SYST_VMS
public static final java.lang.String SYST_VMS
Identifier by which a vms-based ftp server is known throughout the commons-net ftp system.- See Also:
- Constant Field Values
-
SYST_NT
public static final java.lang.String SYST_NT
Identifier by which a WindowsNT-based ftp server is known throughout the commons-net ftp system.- See Also:
- Constant Field Values
-
SYST_OS2
public static final java.lang.String SYST_OS2
Identifier by which an OS/2-based ftp server is known throughout the commons-net ftp system.- See Also:
- Constant Field Values
-
SYST_OS400
public static final java.lang.String SYST_OS400
Identifier by which an OS/400-based ftp server is known throughout the commons-net ftp system.- See Also:
- Constant Field Values
-
SYST_MVS
public static final java.lang.String SYST_MVS
Identifier by which an MVS-based ftp server is known throughout the commons-net ftp system.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
FTPClientConfig
public FTPClientConfig(java.lang.String systemKey)
The main constructor for an FTPClientConfig object- Parameters:
systemKey- key representing system type of the server being connected to. SeeserverSystemKey
-
FTPClientConfig
public FTPClientConfig()
Convenience constructor mainly for use in testing. Constructs a UNIX configuration.
-
FTPClientConfig
public FTPClientConfig(java.lang.String systemKey, java.lang.String defaultDateFormatStr, java.lang.String recentDateFormatStr, java.lang.String serverLanguageCode, java.lang.String shortMonthNames, java.lang.String serverTimeZoneId)Constructor which allows setting of all member fields- Parameters:
systemKey- key representing system type of the server being connected to. SeeserverSystemKeydefaultDateFormatStr- SeedefaultDateFormatStrrecentDateFormatStr- SeerecentDateFormatStrserverLanguageCode- SeeserverLanguageCodeshortMonthNames- SeeshortMonthNamesserverTimeZoneId- SeeserverTimeZoneId
-
-
Method Detail
-
getServerSystemKey
public java.lang.String getServerSystemKey()
Getter for the serverSystemKey property. This property specifies the general type of server to which the client connects. Should be either one of theFTPClientConfig.SYST_*codes or else the fully qualified class name of a parser implementing both theFTPFileEntryParserandConfigurableinterfaces.- Returns:
- Returns the serverSystemKey property.
-
getDefaultDateFormatStr
public java.lang.String getDefaultDateFormatStr()
getter for thedefaultDateFormatStrproperty.- Returns:
- Returns the defaultDateFormatStr property.
-
getRecentDateFormatStr
public java.lang.String getRecentDateFormatStr()
getter for therecentDateFormatStrproperty.- Returns:
- Returns the recentDateFormatStr property.
-
getServerTimeZoneId
public java.lang.String getServerTimeZoneId()
getter for theserverTimeZoneIdproperty.- Returns:
- Returns the serverTimeZoneId property.
-
getShortMonthNames
public java.lang.String getShortMonthNames()
getter for the
shortMonthNamesproperty.- Returns:
- Returns the shortMonthNames.
-
getServerLanguageCode
public java.lang.String getServerLanguageCode()
getter for the
* @return Returns the serverLanguageCode property.serverLanguageCodeproperty.
-
setDefaultDateFormatStr
public void setDefaultDateFormatStr(java.lang.String defaultDateFormatStr)
setter for the defaultDateFormatStr property. This property specifies the main date format that will be used by a parser configured by this configuration to parse file timestamps. If this is not specified, such a parser will use as a default value, the most commonly used format which will be in as used in
en_USlocales.This should be in the format described for
java.text.SimpleDateFormat. property.- Parameters:
defaultDateFormatStr- The defaultDateFormatStr to set.
-
setRecentDateFormatStr
public void setRecentDateFormatStr(java.lang.String recentDateFormatStr)
setter for the recentDateFormatStr property. This property specifies a secondary date format that will be used by a parser configured by this configuration to parse file timestamps, typically those less than a year old. If this is not specified, such a parser will not attempt to parse using an alternate format.
This is used primarily in unix-based systems. This should be in the format described forjava.text.SimpleDateFormat.- Parameters:
recentDateFormatStr- The recentDateFormatStr to set.
-
setServerTimeZoneId
public void setServerTimeZoneId(java.lang.String serverTimeZoneId)
setter for the serverTimeZoneId property. This property allows a time zone to be specified corresponding to that known to be used by an FTP server in file listings. This might be particularly useful to clients such as Ant that try to use these timestamps for dependency checking.
This should be one of the identifiers used by
java.util.TimeZoneto refer to time zones, for example,America/ChicagoorAsia/Rangoon.- Parameters:
serverTimeZoneId- The serverTimeZoneId to set.
-
setShortMonthNames
public void setShortMonthNames(java.lang.String shortMonthNames)
setter for the shortMonthNames property. This property allows the user to specify a set of month names used by the server that is different from those that may be specified using the
serverLanguageCodeproperty.This should be a string containing twelve strings each composed of three characters, delimited by pipe (|) characters. Currently, only 8-bit ASCII characters are known to be supported. For example, a set of month names used by a hypothetical Icelandic FTP server might conceivably be specified as
"jan|feb|mar|apr|maí|jún|júl|ágú|sep|okt|nóv|des".- Parameters:
shortMonthNames- The value to set to the shortMonthNames property.
-
setServerLanguageCode
public void setServerLanguageCode(java.lang.String serverLanguageCode)
setter for the serverLanguageCode property. This property allows user to specify a two-letter ISO-639 language code that will be used to configure the set of month names used by the file timestamp parser. If neither this nor the
shortMonthNamesis specified, parsing will assume English month names, which may or may not be significant, depending on whether the date format(s) specified viadefaultDateFormatStrand/orrecentDateFormatStrare using numeric or alphabetic month names.If the code supplied is not supported here,
en_USmonth names will be used. We are supporting here those language codes which, when ajava.util.Localeis constucted using it, and ajava.text.SimpleDateFormatis constructed using that Locale, the array returned by the SimpleDateFormat'sgetShortMonths()method consists solely of three 8-bit ASCII character strings. Additionally, languages which do not meet this requirement are included if a common alternative set of short month names is known to be used. This means that users who can tell us of additional such encodings may get them added to the list of supported languages by contacting the jakarta-commons-net team.Please note that this attribute will NOT be used to determine a locale-based date format for the language. Experience has shown that many if not most FTP servers outside the United States employ the standard
en_USdate format orderings ofMMM d yyyyandMMM d HH:mmand attempting to deduce this automatically here would cause more problems than it would solve. The date format must be changed via thedefaultDateFormatStrand/orrecentDateFormatStrparameters.- Parameters:
serverLanguageCode- The value to set to the serverLanguageCode property.
-
lookupDateFormatSymbols
public static java.text.DateFormatSymbols lookupDateFormatSymbols(java.lang.String languageCode)
Looks up the supplied language code in the internally maintained table of language codes. Returns a DateFormatSymbols object configured with short month names corresponding to the code. If there is no corresponding entry in the table, the object returned will be that forLocale.US- Parameters:
languageCode- SeeserverLanguageCode- Returns:
- a DateFormatSymbols object configured with short month names
corresponding to the supplied code, or with month names for
Locale.USif there is no corresponding entry in the internal table.
-
getDateFormatSymbols
public static java.text.DateFormatSymbols getDateFormatSymbols(java.lang.String shortmonths)
Returns a DateFormatSymbols object configured with short month names as in the supplied string- Parameters:
shortmonths- This should be as described inshortMonthNames- Returns:
- a DateFormatSymbols object configured with short month names as in the supplied string
-
getSupportedLanguageCodes
public static java.util.Collection getSupportedLanguageCodes()
Returns a Collection of all the language codes currently supported by this class. SeeserverLanguageCodefor a functional descrption of language codes within this system.- Returns:
- a Collection of all the language codes currently supported by this class
-
-