Class FTPFile

  • All Implemented Interfaces:
    java.io.Serializable

    public class FTPFile
    extends java.lang.Object
    implements java.io.Serializable
    The FTPFile class is used to represent information about files stored on an FTP server.
    See Also:
    FTPFileEntryParser, FTPClient.listFiles(), Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Calendar calendar  
      static int DIRECTORY_TYPE
      A constant indicating an FTPFile is a directory.
      static int EXECUTE_PERMISSION
      A constant indicating file execute permission or directory listing permission.
      static int FILE_TYPE
      A constant indicating an FTPFile is a file.
      private java.lang.String group  
      static int GROUP_ACCESS
      A constant indicating group access permissions.
      private int hardLinkCount
      0 is invalid as a link count.
      private java.lang.String link  
      private java.lang.String name  
      private boolean[][] permissions
      If this is null, then list entry parsing failed.
      private java.lang.String rawListing  
      static int READ_PERMISSION
      A constant indicating file/directory read permission.
      private static long serialVersionUID  
      private long size
      0 is valid, so use -1.
      static int SYMBOLIC_LINK_TYPE
      A constant indicating an FTPFile is a symbolic link.
      private int type  
      static int UNKNOWN_TYPE
      A constant indicating an FTPFile is of unknown type.
      private java.lang.String user  
      static int USER_ACCESS
      A constant indicating user access permissions.
      static int WORLD_ACCESS
      A constant indicating world access permissions.
      static int WRITE_PERMISSION
      A constant indicating file/directory write permission.
    • Constructor Summary

      Constructors 
      Constructor Description
      FTPFile()
      Creates an empty FTPFile.
      FTPFile​(java.lang.String rawListing)
      Constructor for use by FTPListParseEngine only.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private char formatType()  
      java.lang.String getGroup()
      Gets the name of the group owning the file.
      int getHardLinkCount()
      Gets the number of hard links to this file.
      java.lang.String getLink()
      If the FTPFile is a symbolic link, this method returns the name of the file being pointed to by the symbolic link.
      java.lang.String getName()
      Gets the name of the file.
      java.lang.String getRawListing()
      Gets the original FTP server raw listing used to initialize the FTPFile.
      long getSize()
      Gets the file size in bytes.
      java.util.Calendar getTimestamp()
      Gets the file timestamp.
      java.time.Instant getTimestampInstant()
      Gets the file timestamp.
      int getType()
      Gets the type of the file (one of the _TYPE constants), e.g., if it is a directory, a regular file, or a symbolic link.
      java.lang.String getUser()
      Gets the name of the user owning the file.
      boolean hasPermission​(int access, int permission)
      Tests if the given access group (one of the _ACCESS constants) has the given access permission (one of the _PERMISSION constants) to the file.
      boolean isDirectory()
      Tests if the file is a directory.
      boolean isFile()
      Tests if the file is a regular file.
      boolean isSymbolicLink()
      Tests if the file is a symbolic link.
      boolean isUnknown()
      Tests if the type of the file is unknown.
      boolean isValid()
      Tests whether an entry is valid or not.
      private java.lang.String permissionToString​(int access)  
      private void readObject​(java.io.ObjectInputStream in)  
      void setGroup​(java.lang.String group)
      Sets the name of the group owning the file.
      void setHardLinkCount​(int links)
      Sets the number of hard links to this file.
      void setLink​(java.lang.String link)
      If the FTPFile is a symbolic link, use this method to set the name of the file being pointed to by the symbolic link.
      void setName​(java.lang.String name)
      Sets the name of the file.
      void setPermission​(int access, int permission, boolean value)
      Sets if the given access group (one of the _ACCESS constants) has the given access permission (one of the _PERMISSION constants) to the file.
      void setRawListing​(java.lang.String rawListing)
      Sets the original FTP server raw listing from which the FTPFile was created.
      void setSize​(long size)
      Sets the file size in bytes.
      void setTimestamp​(java.util.Calendar date)
      Sets the file timestamp.
      void setType​(int type)
      Sets the type of the file (DIRECTORY_TYPE, FILE_TYPE, etc.).
      void setUser​(java.lang.String user)
      Sets the name of the user owning the file.
      java.lang.String toFormattedString()
      Gets a string representation of the FTPFile information.
      java.lang.String toFormattedString​(java.lang.String timezone)
      Gets a string representation of the FTPFile information.
      java.lang.String toString()
      Gets a string representation of the FTPFile information.
      private void writeObject​(java.io.ObjectOutputStream out)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • FILE_TYPE

        public static final int FILE_TYPE
        A constant indicating an FTPFile is a file.
        See Also:
        Constant Field Values
      • DIRECTORY_TYPE

        public static final int DIRECTORY_TYPE
        A constant indicating an FTPFile is a directory.
        See Also:
        Constant Field Values
      • SYMBOLIC_LINK_TYPE

        public static final int SYMBOLIC_LINK_TYPE
        A constant indicating an FTPFile is a symbolic link.
        See Also:
        Constant Field Values
      • UNKNOWN_TYPE

        public static final int UNKNOWN_TYPE
        A constant indicating an FTPFile is of unknown type.
        See Also:
        Constant Field Values
      • USER_ACCESS

        public static final int USER_ACCESS
        A constant indicating user access permissions.
        See Also:
        Constant Field Values
      • GROUP_ACCESS

        public static final int GROUP_ACCESS
        A constant indicating group access permissions.
        See Also:
        Constant Field Values
      • WORLD_ACCESS

        public static final int WORLD_ACCESS
        A constant indicating world access permissions.
        See Also:
        Constant Field Values
      • READ_PERMISSION

        public static final int READ_PERMISSION
        A constant indicating file/directory read permission.
        See Also:
        Constant Field Values
      • WRITE_PERMISSION

        public static final int WRITE_PERMISSION
        A constant indicating file/directory write permission.
        See Also:
        Constant Field Values
      • EXECUTE_PERMISSION

        public static final int EXECUTE_PERMISSION
        A constant indicating file execute permission or directory listing permission.
        See Also:
        Constant Field Values
      • type

        private int type
      • hardLinkCount

        private int hardLinkCount
        0 is invalid as a link count.
      • size

        private long size
        0 is valid, so use -1.
      • rawListing

        private java.lang.String rawListing
      • user

        private java.lang.String user
      • group

        private java.lang.String group
      • name

        private java.lang.String name
      • link

        private java.lang.String link
      • calendar

        private java.util.Calendar calendar
      • permissions

        private final boolean[][] permissions
        If this is null, then list entry parsing failed.
    • Constructor Detail

      • FTPFile

        public FTPFile()
        Creates an empty FTPFile.
      • FTPFile

        FTPFile​(java.lang.String rawListing)
        Constructor for use by FTPListParseEngine only. Used to create FTPFile entries for failed parses
        Parameters:
        rawListing - line that could not be parsed.
        Since:
        3.4
    • Method Detail

      • formatType

        private char formatType()
      • getGroup

        public java.lang.String getGroup()
        Gets 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.
      • getHardLinkCount

        public int getHardLinkCount()
        Gets 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.
      • getLink

        public java.lang.String 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).
      • getName

        public java.lang.String getName()
        Gets the name of the file.
        Returns:
        The name of the file.
      • getRawListing

        public java.lang.String getRawListing()
        Gets the original FTP server raw listing used to initialize the FTPFile.
        Returns:
        The original FTP server raw listing used to initialize the FTPFile.
      • getSize

        public long getSize()
        Gets the file size in bytes.
        Returns:
        The file size in bytes.
      • getTimestamp

        public java.util.Calendar getTimestamp()
        Gets the file timestamp. This usually the last modification time.
        Returns:
        A Calendar instance representing the file timestamp.
      • getTimestampInstant

        public java.time.Instant getTimestampInstant()
        Gets the file timestamp. This usually the last modification time.
        Returns:
        A Calendar instance representing the file timestamp.
        Since:
        3.9.0
      • getType

        public int getType()
        Gets the type of the file (one of the _TYPE constants), e.g., if it is a directory, a regular file, or a symbolic link.
        Returns:
        The type of the file.
      • getUser

        public java.lang.String getUser()
        Gets 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.
      • hasPermission

        public boolean hasPermission​(int access,
                                     int permission)
        Tests if the given access group (one of the _ACCESS constants) has the given access permission (one of the _PERMISSION constants) to the file.
        Parameters:
        access - The access group (one of the _ACCESS constants)
        permission - The access permission (one of the _PERMISSION constants)
        Returns:
        true if isValid() is true and the associated permission is set; false otherwise.
        Throws:
        java.lang.ArrayIndexOutOfBoundsException - if either of the parameters is out of range
      • isDirectory

        public boolean isDirectory()
        Tests if the file is a directory.
        Returns:
        true if the file is of type DIRECTORY_TYPE, false if not.
      • isFile

        public boolean isFile()
        Tests if the file is a regular file.
        Returns:
        true if the file is of type FILE_TYPE, false if not.
      • isSymbolicLink

        public boolean isSymbolicLink()
        Tests if the file is a symbolic link.
        Returns:
        true if the file is of type SYMBOLIC_LINK_TYPE, false if not.
      • isUnknown

        public boolean isUnknown()
        Tests 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()
        Tests whether an entry is valid or not. If the entry is invalid, only the getRawListing() method will be useful. Other methods may fail. Used in conjunction with list parsing that preserves entries that failed to parse.
        Returns:
        true if the entry is valid; false otherwise
        Since:
        3.4
        See Also:
        FTPClientConfig.setUnparseableEntries(boolean)
      • permissionToString

        private java.lang.String permissionToString​(int access)
      • readObject

        private void readObject​(java.io.ObjectInputStream in)
      • setGroup

        public void setGroup​(java.lang.String group)
        Sets 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.
      • setHardLinkCount

        public void setHardLinkCount​(int links)
        Sets 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.
      • setLink

        public void setLink​(java.lang.String link)
        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.
      • setName

        public void setName​(java.lang.String name)
        Sets the name of the file.
        Parameters:
        name - The name of the file.
      • setPermission

        public void setPermission​(int access,
                                  int permission,
                                  boolean value)
        Sets if the given access group (one of the _ACCESS constants) has the given access permission (one of the _PERMISSION constants) to the file.
        Parameters:
        access - The access group (one of the _ACCESS constants)
        permission - The access permission (one of the _PERMISSION constants)
        value - true if permission is allowed, false if not.
        Throws:
        java.lang.ArrayIndexOutOfBoundsException - if either of the parameters is out of range
      • setRawListing

        public void setRawListing​(java.lang.String rawListing)
        Sets the original FTP server raw listing from which the FTPFile was created.
        Parameters:
        rawListing - The raw FTP server listing.
      • setSize

        public void setSize​(long size)
        Sets the file size in bytes.
        Parameters:
        size - The file size in bytes.
      • setTimestamp

        public void setTimestamp​(java.util.Calendar date)
        Sets 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.
      • setType

        public void setType​(int type)
        Sets the type of the file (DIRECTORY_TYPE, FILE_TYPE, etc.).
        Parameters:
        type - The integer code representing the type of the file.
      • setUser

        public void setUser​(java.lang.String user)
        Sets 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.
      • toFormattedString

        public java.lang.String toFormattedString()
        Gets a string representation of the FTPFile information. This currently mimics the UNIX listing format. This method uses the time zone 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, use getRawListing() instead.

        Returns:
        A string representation of the FTPFile information.
        Since:
        3.0
      • toFormattedString

        public java.lang.String toFormattedString​(java.lang.String timezone)
        Gets 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, use getRawListing() instead.

        Parameters:
        timezone - the time zone to use for displaying the time stamp If null, then use the Calendar (getTimestamp()) entry
        Returns:
        A string representation of the FTPFile information.
        Since:
        3.4
      • toString

        public java.lang.String toString()
        Gets a string representation of the FTPFile information. Delegates to getRawListing()
        Overrides:
        toString in class java.lang.Object
        Returns:
        A string representation of the FTPFile information.
        See Also:
        getRawListing()
      • writeObject

        private void writeObject​(java.io.ObjectOutputStream out)