Checking file size with FTPClient

I was wandering if there is a way of checking a file size using File Transfer Protocol prior to the file's download.
I am developing an application that handles very large files
(15 - 20M), and one of the requirements is not to download a file if it doesn't conform to a certain size requirements.
Please help.
Thank you in advance.

When you are using the FTPClient (if you are using the one that is part of the java library) you can issue a ls command which returns a list of the files with sizes, similar to the unix ls -l command. Take the list and extract the file sizes.

Ok I agree. What you actually need to do is use the SIZE ftp command. This command returns to you the size of a given file. I assume that you are using the FTPClient in the java library. I'm afraid that this option is closed for you since the interface is protected. There are few options for you to take:
1. write the whole communication layer yourself and then you can issue the SIZE command to the ftp server.
2. Decompile the FTPClient so that you can insert your own commands (I did that this require a lot of work!).
3. Search the web for ftp clients implementations. www.gamelan.com would be a good place to start.

If you leave me your e-mail address I will send you a Java FTP client I found on the Internet (do not remeber where) which looks quite reasonable. I has an FTP client implementation as well as the GUI client which you do not have to use.

The SIZE command is not a part of the FTP standard, and is not supported by many FTP servers, so it can't be used as the ultimate solution.

The best solution to the problem is to use FTP's LIST command, and extract the file size from the returned directory list (the solution you proposed at the begining).
It is true that the returned list would depend on FTP server's OS. However, vast majority of FTP servers returns directory listings whose layout complies to standard UNIX listing (the only exception is Win95). So, if you build your FTPClient knowing these facts, you can end up with relativly safe solution.
Or, you can ask your boss to change the specs, as I did.

You are welcome. Note however that there are still operations that are not supported by the default FTPClient. The most common operation that I needed thats not implemented is MKDIR. If you want to implement one of those - you will have no choice but to use the FTPClient source I sent you.
Good luck,
G.

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects.
Interface Comparable is used to allow objects of a cl…

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application.
For the purposes of this article, I will be u…

Viewers will learn about the different types of variables in Java and how to declare them.
Decide the type of variable desired:
Put the keyword corresponding to the type of variable in front of the variable name:
Use the equal sign to assign a v…

How to fix incompatible JVM issue while installing Eclipse
While installing Eclipse in windows, got one error like above and unable to proceed with the installation.
This video describes how to successfully install Eclipse.
How to solve incompa…