如何获取FTP文件的信息 [英] How to get info of an FTPFile
问题描述
我正在使用ApacheCommons连接到服务器并获取特定文件的信息。我正在寻找一个方法,如 FTPFile file = ftpclient.getFile(path);
或类似的东西,所以我可以给它文件的路径然后能够获取有关该文件的信息。通过信息我的意思是 file.getName()
或 file.lendth()
。
我找到的唯一方法是使用列表方法,例如 listFiles(路径)
但它需要使用 for-loop
依此类推。但有没有更好的方法或更直接?
I am using ApacheCommons to connect to a server and get information of a specific file. I am looking for a method like FTPFile file = ftpclient.getFile(path);
or something like this, so I can give it the path of the file and then be able to get info about that file. By info I mean file.getName()
or file.lendth()
.
The only way I found is using listing methods such as listFiles(path)
but it requires using for-loop
and so on. But is there any better way or more straight forward?
推荐答案
使用 FTPClient.mlistFile
:
public FTPFile mlistFile(String pathname)
使用MLST命令获取文件详细信息
Get file details using the MLST command
当然,如果您的服务器支持 modern MLST
命令。
Of course, this will work only, if your server supports the modern MLST
command.
如果没有,则必须为每个文件属性使用专用命令。类似文件大小的 SIZE
(Apache Commons本身不支持)或 MDTM
用于文件修改时间(< a href =https://commons.apache.org/proper/commons-net/apidocs/org/apache/commons/net/ftp/FTPClient.html#getModificationTime(java.lang.String) =nofollow noreferrer > FTPClient.getModificationTime
)。
If not, you would have to use a dedicated command for each file property. Like the SIZE
for file size (not supported natively by Apache Commons) or the MDTM
for file modification time (the FTPClient.getModificationTime
).
这篇关于如何获取FTP文件的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!