问题
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