How to get info of an FTPFile

北城余情 提交于 2019-12-08 03:27:53

问题


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).



来源:https://stackoverflow.com/questions/29198422/how-to-get-info-of-an-ftpfile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!