How to get info of an FTPFile

Tags: , ,



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?

Answer

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



Source: stackoverflow