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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to download X bytes from a file using ftp or http?
# 1  
Old 07-17-2009
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
# 2  
Old 07-17-2009
If you have curl use the -r/--range option.
To download the first 500 bytes:

Code:
curl -Or0-499 <url>

# 3  
Old 07-17-2009
Thx for the response, but I do not have curl..
# 4  
Old 07-17-2009
OK,
then use Perl:

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

# 5  
Old 07-17-2009
Thx rodoulov, it just worked fine with anonymous credentials. great!!. Looking out how I can make it work with real username/password..
# 6  
Old 07-17-2009
Check the documentation at cpan.org (credentials):

Code:
$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.

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unable to Download File from FTP

Hi, I am trying to download files from FTP using below FTP code. x=$(TZ=CST date +%Y%m%d) host='xxx.xx.xxx.xxx' user='userX' pass='Password' echo "Connecting to FTP Host -- $host....." echo $x a=$(ftp -v -n -i << ! open $host user "$user" $pass cd /rose/yellow/ mget... (6 Replies)
Discussion started by: rramkrishnas
6 Replies

2. Programming

Download http picture using C++

Dear all, I am working on writing the script which can read a file (having the html path for some pictures) and download those picture in the given local directory. Please find my iniatitve here, however I am still not able to figure out the 'download' command. Any help is appreciated. ... (1 Reply)
Discussion started by: emily
1 Replies

3. Shell Programming and Scripting

Wanted to download the yesterday's file through FTP

Hello, Wanted to download the yesturday's or current date-1 file through shell script Mode: FTP OS: AIX if today is 13th May then file would be available as below. File Pattern:201401148682_daily_2014-05-12.txt.zip Help.. (4 Replies)
Discussion started by: Riverstone
4 Replies

4. Shell Programming and Scripting

FTP File download

Hi, I have few files at FTP location and have written a script to download the same from ftp based on the sysdate - 1, however with the below code I am unable to download the files from FTP. x=`TZ=CST+24 date +%Y%m%d` mget Daily_BIH_$x_NEW.tar.gz can anyone please help me in... (10 Replies)
Discussion started by: rramkrishnas
10 Replies

5. UNIX for Dummies Questions & Answers

X bytes of 0, Y bytes of random data, Z bytes of 5, T bytes of 1. ??

Hello guys. I really hope someone will help me with this one.. So, I have to write this script who: - creates a file home/student/vmdisk of 10 mb - formats that file to ext3 - mounts that partition to /mnt/partition - creates a file /mnt/partition/data. In this file, there will... (1 Reply)
Discussion started by: razolo13
1 Replies

6. Shell Programming and Scripting

File download from HTTP::DAV

Hi, I have DOX server. I have to download latest file using HTTP:: DAV. at present am using get method with file name ABC*, it downloads all the files. But I need to download only latest file. Any help?? Thanks, Raja. (0 Replies)
Discussion started by: smr_rashmy
0 Replies

7. Shell Programming and Scripting

download specified file from ftp server

Hi all, I'm having problems downloading files from ftp server. I have to download only those files that name starts with YYYYMMDD.But file comes like the format "20080624221035.TXT".Also how i can get list of all file names with in specified folder. Here i paste my code ftp -vn... (1 Reply)
Discussion started by: vaskarbasak
1 Replies

8. Shell Programming and Scripting

Remove first N bytes and last N bytes from a binary file on AIX.

Hi all, Does anybody know or guide me on how to remove the first N bytes and the last N bytes from a binary file? Is there any AWK or SED or any command that I can use to achieve this? Your help is greatly appreciated!! Best Regards, Naveen. (1 Reply)
Discussion started by: naveendronavall
1 Replies

9. UNIX for Dummies Questions & Answers

file size in bytes is different in ftp and local pc

Hi how can it be that say i have text (xls) file that is 661 bytes when i upload it to Solaris ftp its becomes 650 byes and when i downloading it back its again 661 bytes both in my local pc and Solaris ftp the file remains not corrupted and valid (2 Replies)
Discussion started by: umen
2 Replies

10. UNIX for Dummies Questions & Answers

GCC via Http-Download?

Hello all, i am looking for a long time now after GCC. I cannot download it via FTP, thatīs the problem. Is somebody here who knows where i can get it over HTTP?? Regards and Thank You, Chris (5 Replies)
Discussion started by: cyberbloodgoat
5 Replies
Login or Register to Ask a Question