Package org.apache.commons.net.ftp
Class FTPFile
java.lang.Object
org.apache.commons.net.ftp.FTPFile
- All Implemented Interfaces:
Serializable
The FTPFile class is used to represent information about files stored
on an FTP server.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Calendarprivate Stringprivate intprivate Stringprivate Stringprivate final boolean[][]private Stringprivate longprivate intprivate Stringstatic final intA constant indicating an FTPFile is a directory.static final intA constant indicating file execute permission or directory listing permission.static final intA constant indicating an FTPFile is a file.static final intA constant indicating group access permissions.static final intA constant indicating file/directory read permission.private static final longstatic final intA constant indicating an FTPFile is a symbolic link.static final intA constant indicating an FTPFile is of unknown type.static final intA constant indicating user access permissions.static final intA constant indicating world access permissions.static final intA constant indicating file/directory write permission. -
Constructor Summary
ConstructorsConstructorDescriptionFTPFile()Creates an empty FTPFile.Constructor for use byFTPListParseEngineonly. -
Method Summary
Modifier and TypeMethodDescriptionprivate chargetGroup()Returns the name of the group owning the file.intReturn the number of hard links to this file.getLink()If the FTPFile is a symbolic link, this method returns the name of the file being pointed to by the symbolic link.getName()Return the name of the file.Get the original FTP server raw listing used to initialize the FTPFile.longgetSize()Return the file size in bytes.Returns the file timestamp.intgetType()Return the type of the file (one of the_TYPEconstants), e.g., if it is a directory, a regular file, or a symbolic link.getUser()Returns the name of the user owning the file.booleanhasPermission(int access, int permission) Determines if the given access group (one of the_ACCESSconstants) has the given access permission (one of the_PERMISSIONconstants) to the file.booleanDetermine if the file is a directory.booleanisFile()Determine if the file is a regular file.booleanDetermine if the file is a symbolic link.booleanDetermine if the type of the file is unknown.booleanisValid()Used to indicate whether an entry is valid or not.private StringpermissionToString(int access) voidSet the name of the group owning the file.voidsetHardLinkCount(int links) Set the number of hard links to this file.voidIf the FTPFile is a symbolic link, use this method to set the name of the file being pointed to by the symbolic link.voidSet the name of the file.voidsetPermission(int access, int permission, boolean value) Set if the given access group (one of the_ACCESSconstants) has the given access permission (one of the_PERMISSIONconstants) to the file.voidsetRawListing(String rawListing) Set the original FTP server raw listing from which the FTPFile was created.voidsetSize(long size) Set the file size in bytes.voidsetTimestamp(Calendar date) Set the file timestamp.voidsetType(int type) Set the type of the file (DIRECTORY_TYPE,FILE_TYPE, etc.).voidSet the name of the user owning the file.Returns a string representation of the FTPFile information.toFormattedString(String timezone) Returns a string representation of the FTPFile information.toString()Returns a string representation of the FTPFile information.
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
FILE_TYPE
public static final int FILE_TYPEA constant indicating an FTPFile is a file.- See Also:
-
DIRECTORY_TYPE
public static final int DIRECTORY_TYPEA constant indicating an FTPFile is a directory.- See Also:
-
SYMBOLIC_LINK_TYPE
public static final int SYMBOLIC_LINK_TYPEA constant indicating an FTPFile is a symbolic link.- See Also:
-
UNKNOWN_TYPE
public static final int UNKNOWN_TYPEA constant indicating an FTPFile is of unknown type.- See Also:
-
USER_ACCESS
public static final int USER_ACCESSA constant indicating user access permissions.- See Also:
-
GROUP_ACCESS
public static final int GROUP_ACCESSA constant indicating group access permissions.- See Also:
-
WORLD_ACCESS
public static final int WORLD_ACCESSA constant indicating world access permissions.- See Also:
-
READ_PERMISSION
public static final int READ_PERMISSIONA constant indicating file/directory read permission.- See Also:
-
WRITE_PERMISSION
public static final int WRITE_PERMISSIONA constant indicating file/directory write permission.- See Also:
-
EXECUTE_PERMISSION
public static final int EXECUTE_PERMISSIONA constant indicating file execute permission or directory listing permission.- See Also:
-
_type
private int _type -
_hardLinkCount
private int _hardLinkCount -
_size
private long _size -
_rawListing
-
_user
-
_group
-
_name
-
_link
-
_date
-
_permissions
private final boolean[][] _permissions
-
-
Constructor Details
-
FTPFile
public FTPFile()Creates an empty FTPFile. -
FTPFile
FTPFile(String rawListing) Constructor for use byFTPListParseEngineonly. Used to create FTPFile entries for failed parses- Parameters:
rawListing- line that could not be parsed.- Since:
- 3.4
-
-
Method Details
-
setRawListing
Set the original FTP server raw listing from which the FTPFile was created.- Parameters:
rawListing- The raw FTP server listing.
-
getRawListing
Get the original FTP server raw listing used to initialize the FTPFile.- Returns:
- The original FTP server raw listing used to initialize the FTPFile.
-
isDirectory
public boolean isDirectory()Determine if the file is a directory.- Returns:
- True if the file is of type
DIRECTORY_TYPE, false if not.
-
isFile
public boolean isFile()Determine if the file is a regular file.- Returns:
- True if the file is of type
FILE_TYPE, false if not.
-
isSymbolicLink
public boolean isSymbolicLink()Determine if the file is a symbolic link.- Returns:
- True if the file is of type
UNKNOWN_TYPE, false if not.
-
isUnknown
public boolean isUnknown()Determine if the type of the file is unknown.- Returns:
- True if the file is of type
UNKNOWN_TYPE, false if not.
-
isValid
public boolean isValid()Used to indicate whether an entry is valid or not. If the entry is invalid, only thegetRawListing()method will be useful. Other methods may fail. Used in conjunction with list parsing that preseverves entries that failed to parse.- Returns:
- true if the entry is valid
- Since:
- 3.4
- See Also:
-
setType
public void setType(int type) Set the type of the file (DIRECTORY_TYPE,FILE_TYPE, etc.).- Parameters:
type- The integer code representing the type of the file.
-
getType
public int getType()Return the type of the file (one of the_TYPEconstants), e.g., if it is a directory, a regular file, or a symbolic link.- Returns:
- The type of the file.
-
setName
Set the name of the file.- Parameters:
name- The name of the file.
-
getName
Return the name of the file.- Returns:
- The name of the file.
-
setSize
public void setSize(long size) Set the file size in bytes.- Parameters:
size- The file size in bytes.
-
getSize
public long getSize()Return the file size in bytes.- Returns:
- The file size in bytes.
-
setHardLinkCount
public void setHardLinkCount(int links) Set the number of hard links to this file. This is not to be confused with symbolic links.- Parameters:
links- The number of hard links to this file.
-
getHardLinkCount
public int getHardLinkCount()Return the number of hard links to this file. This is not to be confused with symbolic links.- Returns:
- The number of hard links to this file.
-
setGroup
Set the name of the group owning the file. This may be a string representation of the group number.- Parameters:
group- The name of the group owning the file.
-
getGroup
Returns the name of the group owning the file. Sometimes this will be a string representation of the group number.- Returns:
- The name of the group owning the file.
-
setUser
Set the name of the user owning the file. This may be a string representation of the user number;- Parameters:
user- The name of the user owning the file.
-
getUser
Returns the name of the user owning the file. Sometimes this will be a string representation of the user number.- Returns:
- The name of the user owning the file.
-
setLink
If the FTPFile is a symbolic link, use this method to set the name of the file being pointed to by the symbolic link.- Parameters:
link- The file pointed to by the symbolic link.
-
getLink
If the FTPFile is a symbolic link, this method returns the name of the file being pointed to by the symbolic link. Otherwise it returns null.- Returns:
- The file pointed to by the symbolic link (null if the FTPFile is not a symbolic link).
-
setTimestamp
Set the file timestamp. This usually the last modification time. The parameter is not cloned, so do not alter its value after calling this method.- Parameters:
date- A Calendar instance representing the file timestamp.
-
getTimestamp
Returns the file timestamp. This usually the last modification time.- Returns:
- A Calendar instance representing the file timestamp.
-
setPermission
public void setPermission(int access, int permission, boolean value) Set if the given access group (one of the_ACCESSconstants) has the given access permission (one of the_PERMISSIONconstants) to the file.- Parameters:
access- The access group (one of the_ACCESSconstants)permission- The access permission (one of the_PERMISSIONconstants)value- True if permission is allowed, false if not.- Throws:
ArrayIndexOutOfBoundsException- if either of the parameters is out of range
-
hasPermission
public boolean hasPermission(int access, int permission) Determines if the given access group (one of the_ACCESSconstants) has the given access permission (one of the_PERMISSIONconstants) to the file.- Parameters:
access- The access group (one of the_ACCESSconstants)permission- The access permission (one of the_PERMISSIONconstants)- Returns:
- true if
isValid()istrue &&the associated permission is set;falseotherwise. - Throws:
ArrayIndexOutOfBoundsException- if either of the parameters is out of range
-
toString
Returns a string representation of the FTPFile information. -
toFormattedString
Returns a string representation of the FTPFile information. This currently mimics the Unix listing format. This method uses the timezone of the Calendar entry, which is the server time zone (if one was provided) otherwise it is the local time zone.Note: if the instance is not valid
isValid(), no useful information can be returned. In this case, usegetRawListing()instead.- Returns:
- A string representation of the FTPFile information.
- Since:
- 3.0
-
toFormattedString
Returns a string representation of the FTPFile information. This currently mimics the Unix listing format. This method allows the Calendar time zone to be overridden.Note: if the instance is not valid
isValid(), no useful information can be returned. In this case, usegetRawListing()instead.- Parameters:
timezone- the timezone to use for displaying the time stamp Ifnull, then use the Calendar entry timezone- Returns:
- A string representation of the FTPFile information.
- Since:
- 3.4
-
formatType
private char formatType() -
permissionToString
-