How to download X bytes from a file using ftp or http?

Hi,

I have a simple ftp shell script which can download the entire file, however I want to know if there is anyway that I can download only the partial content, say X bytes from a file. If so, how I can do it using ftp and http..

Here is my sample script

#!/bin/sh

HOST='xyz.com'
USER='anonymous'
PASSWD='xxxxx'
/usr/bin/ftp -v -n $HOST << _FTP
quote USER $USER
quote PASS $PASSWD
bin
prompt off
cd <dir>
get <remote-filename> <local-filename>
bye

_FTP

If you have curl use the -r/--range option.
To download the first 500 bytes:

curl -Or0-499 <url>

Thx for the response, but I do not have curl..

OK,
then use Perl:

perl -MLWP::UserAgent -e'
  $ua = LWP::UserAgent->new( max_size => <your_size_in_bytes> );
  $r = $ua->get( "<your_url>", ":content_file" => "<dest_file_name>" );
    '    

Thx rodoulov, it just worked fine with anonymous credentials. great!!. Looking out how I can make it work with real username/password..

Check the documentation at cpan.org (credentials):

$ua->credentials( $netloc, $realm, $uname, $pass )
Set the user name and password to be used for a realm. 
It is often more useful to specialize the get_basic_credentials() method instead.