<!-- ======== START OF CLASS DATA ======== -->
org.apache.commons.net.ftp
Class FTPFile
- java.lang.Object
-
- org.apache.commons.net.ftp.FTPFile
-
- All Implemented Interfaces:
- Serializable
public class FTPFile extends Object implements Serializable
The FTPFile class is used to represent information about files stored on an FTP server.- See Also:
FTPFileEntryParser
,FTPClient.listFiles(java.lang.String)
, Serialized Form
- <!-- =========== FIELD SUMMARY =========== -->
-
<!-- -->
Field Summary
Fields
Modifier and Type Field and Description 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.static int
GROUP_ACCESS
A constant indicating group access permissions.static int
READ_PERMISSION
A constant indicating file/directory read permission.static int
SYMBOLIC_LINK_TYPE
A constant indicating an FTPFile is a symbolic link.static int
UNKNOWN_TYPE
A constant indicating an FTPFile is of unknown type.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 and Description FTPFile()
Creates an empty FTPFile.
-
<!-- -->
Method Summary
Methods
Modifier and Type Method and Description String
getGroup()
Returns the name of the group owning the file.int
getHardLinkCount()
Return the number of hard links to this file.String
getLink()
If the FTPFile is a symbolic link, this method returns the name of the file being pointed to by the symbolic link.String
getName()
Return the name of the file.String
getRawListing()
Get the original FTP server raw listing used to initialize the FTPFile.long
getSize()
Return the file size in bytes.Calendar
getTimestamp()
Returns the file timestamp.int
getType()
Return the type of the file (one of the_TYPE
constants), e.g., if it is a directory, a regular file, or a symbolic link.String
getUser()
Returns the name of the user owning the file.boolean
hasPermission(int access, int permission)
Determines 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()
Determine if the file is a directory.boolean
isFile()
Determine if the file is a regular file.boolean
isSymbolicLink()
Determine if the file is a symbolic link.boolean
isUnknown()
Determine if the type of the file is unknown.boolean
isValid()
Used to indicate whether an entry is valid or not.void
setGroup(String group)
Set the name of the group owning the file.void
setHardLinkCount(int links)
Set the number of hard links to this file.void
setLink(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(String name)
Set the name of the file.void
setPermission(int access, int permission, boolean value)
Set 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(String rawListing)
Set the original FTP server raw listing from which the FTPFile was created.void
setSize(long size)
Set the file size in bytes.void
setTimestamp(Calendar date)
Set the file timestamp.void
setType(int type)
Set the type of the file (DIRECTORY_TYPE
,FILE_TYPE
, etc.).void
setUser(String user)
Set the name of the user owning the file.String
toFormattedString()
Returns a string representation of the FTPFile information.String
toFormattedString(String timezone)
Returns a string representation of the FTPFile information.String
toString()
Returns a string representation of the FTPFile information.
-
<!-- -->
- <!-- ============ FIELD DETAIL =========== -->
-
<!-- -->
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
-
-
<!-- -->
Constructor Detail
<!-- -->-
FTPFile
public FTPFile()
Creates an empty FTPFile.
-
-
<!-- -->
Method Detail
<!-- -->-
setRawListing
public void setRawListing(String rawListing)
Set the original FTP server raw listing from which the FTPFile was created.- Parameters:
rawListing
- The raw FTP server listing.
-
getRawListing
public String 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:
FTPClientConfig.setUnparseableEntries(boolean)
-
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_TYPE
constants), e.g., if it is a directory, a regular file, or a symbolic link.- Returns:
- The type of the file.
-
setName
public void setName(String name)
Set the name of the file.- Parameters:
name
- 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
public void setGroup(String group)
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
public String 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
public void setUser(String user)
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
public String 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
public void setLink(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.
-
getLink
public 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).
-
setTimestamp
public void setTimestamp(Calendar date)
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
public Calendar 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_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:
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_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()
istrue &&
the associated permission is set;false
otherwise.- Throws:
ArrayIndexOutOfBoundsException
- if either of the parameters is out of range
-
toString
public String toString()
Returns a string representation of the FTPFile information.- Overrides:
toString
in classObject
- Returns:
- A string representation of the FTPFile information.
-
toFormattedString
public String 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
public String toFormattedString(String timezone)
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
-
-
<!-- -->
相关推荐
### FTPServer与FTPFile在文件传输中的应用 #### FTPServer简介 FTPServer是指提供文件传输服务的服务器软件,主要用于在网络环境中实现文件的上传、下载等功能。FTP(File Transfer Protocol)是一种用于在网络上...
### FTPFile及FTP Server 使用说明 #### 一、FTP简介 FTP(File Transfer Protocol)是一种用于在网络上进行文件传输的标准协议。它允许用户将文件从一台计算机传输到另一台计算机上,并支持基本的文件管理操作,如...
FTP(File Transfer Protocol)是一种用于在网络上进行文件传输的标准协议,广泛应用于网站的文件上传和下载。在PHP中,我们可以利用内置的ftp扩展来实现FTP功能,这个扩展提供了一系列的函数来处理FTP连接、文件...
标题"Ftp_class"所指的是一个基于PHP编写的FTP(File Transfer Protocol)上传类。FTP是一种网络协议,用于在计算机之间进行文件传输。这个类库包含了处理FTP连接、上传、下载等任务所需的功能,使得开发者能够方便...
public FtpTemplate ftpTemplate(SessionFactory<FTPFile> sessionFactory) { return new FtpTemplate(sessionFactory); } } ``` 有了这些配置,我们就可以编写业务逻辑来实现文件上传和下载功能。例如,我们...
【WinInet_FTP_Class.zip_FtpEx_ftp】是一个包含FTP客户端实现的代码压缩包,主要用于使用WinInet库进行FTP(File Transfer Protocol)文件传输。FTP是一种用于在网络上进行文件传输的标准协议,广泛应用于网站内容...
Public class FileValidation 图片检测类 Public class FormulaHelper 数学函数帮助类 Public class FTPClient Ftp客户端相关类 Public class FTPHelper Ftp帮助类 Public class GridViewExport GridView导出...
这个jar包包含了所有执行FTP操作所需的类和方法,如`FTPClient`、`FTPFile`等。使用这个库,开发者可以方便地创建FTP连接,进行被动模式或主动模式的数据传输,管理文件权限,处理断点续传等复杂场景。 以下是一个...
private static boolean needToUpdate(FTPFile file) { // 这里应该添加实际的逻辑,比较本地文件和FTP文件的修改时间 return true; // 临时返回值,实际应根据时间判断 } } ``` 在这个示例中,我们首先连接到...
FTP (File Transfer Protocol) 是一种用于在网络上进行文件传输的标准协议,广泛应用于Web开发、系统管理和数据备份等场景。Java作为一种跨平台的编程语言,提供了多种库来实现FTP操作,如Apache Commons Net库。本...
在Java编程中,FTP(File Transfer Protocol)文件服务器的交互是一项常见的任务,它允许程序员从或向远程服务器传输文件。本篇文章将详细讲解如何使用Java实现FTP文件的上传与下载,以及相关的操作如创建文件夹、...
FTPFile[] list = client.list("*.jpg"); //显示文件或文件夹的修改时间 java.util.Date md = client.modifiedDate("filename.ext"); //上传和下载文件 //下载服务器上remoteFile.ext 下载到本地 localFile.ext ...
import net.sf.jftp.net.ConnectionHandler import ...import net.sf.jftp.net.FtpConnection ... import java.io.* ...// this class download a file via anonymous ftp and shows output.
FTP(File Transfer Protocol)是一种用于在网络上进行文件传输的标准协议,广泛应用于网站内容的发布和其他文件管理场景。在PHP中,通过FTP类可以方便地与FTP服务器交互,进行文件的上传、下载、删除等操作。 描述...
$ftp->upload('/local/file.txt', '/remote/path/file.txt'); $ftp->disconnect(); ``` 总之,PHP FTP操作类是提高开发效率、简化FTP操作的有效工具。它将复杂的FTP通信封装起来,使得开发者可以更加专注于业务逻辑...
FTPFile[] files = ftp.listFiles(); for (FTPFile file : files) { if (Arrays.stream(filters).anyMatch(file.getName()::endsWith)) { // 下载符合条件的文件 } } ``` 5. **配置文件使用**:`config....
FTP(File Transfer Protocol)是一种用于在互联网上进行文件传输的标准协议。在 ThinPHP 框架下实现 FTP 图片上传,通常涉及到几个关键步骤和技术点,包括 FTP 客户端库的使用、文件上传处理、配置管理以及错误处理...
在实际开发中,为了代码的健壮性和可维护性,通常会封装这些操作到一个FTP类中,如提供的`ftp_class`文件可能就是一个这样的实现。这个类可能包含构造函数来处理连接和登录,方法如`download`、`upload`、`create...
例如,你可以使用`FTPClient`类建立连接,`FTPFile`类来处理服务器上的文件信息,以及`FTPReply`类检查服务器的响应代码。 以下是一个基本的Java FTP客户端操作示例: ```java import org.apache.commons.net.ftp....