Solved

Checking file size with FTPClient

Posted on 1998-07-30
11
201 Views
Last Modified: 2010-04-16
Hi Everybody,

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.
0
Comment
Question by:apetrovic
  • 6
  • 4
11 Comments
 
LVL 6

Expert Comment

by:gadio
ID: 1229243
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.
0
 

Author Comment

by:apetrovic
ID: 1229244
Hi gadio,
Thanks for your answer.
I was thinking about the same solution, but resulted list would be dependent upon server's operating system, which is unacceptable in the specifications I have.
0
 
LVL 6

Expert Comment

by:gadio
ID: 1229245
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.

0
 

Author Comment

by:apetrovic
ID: 1229246
It seems that the first option you proposed is inevitable (I already searched Gamelan and a few other sites, without any success).
Thanks for your help gadio.
0
 
LVL 5

Expert Comment

by:msmolyak
ID: 1229247
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.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 6

Expert Comment

by:gadio
ID: 1229248
You are welcome. By the way, I can also email you the decompiled FTPClient and you can change it to work for you.
0
 

Author Comment

by:apetrovic
ID: 1229249
You can email me at apetrovic@imagictv.com
0
 
LVL 6

Expert Comment

by:gadio
ID: 1229250
Done.
If this solves your problem, tell me and I'll "answer" this question.
0
 
LVL 6

Accepted Solution

by:
gadio earned 100 total points
ID: 1229251
Hope that this solved your problem.
0
 

Author Comment

by:apetrovic
ID: 1229252
Hi gadio,

Sorry I did not reply sooner.

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.

Once again thanks for your help,

0
 
LVL 6

Expert Comment

by:gadio
ID: 1229253
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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now