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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Use the FTPClient.mlistFile
:
public FTPFile mlistFile(String pathname)
Get file details using the MLST command
Of course, this will work only, if your server supports the modern MLST
command.
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
).