getting the file size from ftp server
1 posts in topic
Flat View  Flat View

Posted By:   pushkar_prakash
Posted On:   Friday, December 6, 2002 10:51 AM

how to get the file size of a file stored on a ftp server
before starting to read from the inputstream using the networking api.
I tried the URLConnection.getContentLength() but it works only with
the http urls not with ftp urls.

Re: getting the file size from ftp server

Posted By:   Prashanth_Sukumaran  
Posted On:   Friday, December 6, 2002 11:07 AM

Hi Pushkar,

One easy way is to first issue an ls command.

For eg., if the name of the file is nohup.out


ls -l nohup.out

will give

-rw-r--r-- 1 prash ibsg 202353 Dec 5 18:18 nohup.out

So the fifth column would be the file size. Use a string tokenizer on this line. I think you should find the same behaviour/output in all unix flavours.

I hope this helps


PS: URLConnection.getContentLength() reads form the HTTP Response Header and gives you the ContentLength. Also you will not always get the content length. It needs to be configured on the server that the Content Length is to be sent in the HTTP Response Header.
About | Sitemap | Contact