Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm working on a tool to get some data that is buried within a very large file on a remote system. It would be impractical to copy the entire file over, and all of the data I need exists within the first 1000 or so bytes of the file. I know that I can start a get and just cancel it with ^C to get a partial file, however this would be difficult (if not impossible) to automate with any consistency.

I would like to tell my ftp client to only grab x bytes of the remote file and quit as soon as it has them. I've found a few windows clients that do partial downloads, but I haven't found anything in the ftp man page and documentation online is sparse.

I found this HowTo: http://cdsarc.u-strasbg.fr/doc/ftp.htx that suggests the following syntax:

ftp> get bigfile.dat:0-5000 bigfile.nxt

It is unclear to me if this is supposed to be implemented in the client or the server, but in either case, it doesn't seem to work in my environment. (Standard linux ftp client connecting to an FTP server running on z/OS)

Even when trying between the linux standard ftp client and a filezilla server on windows, my attempts fail in the following way

ftp> get green.gif:0-10c
local: green.gif:0-10c remote: green.gif:0-10c
227 Entering Passive Mode (9,42,91,226,4,105)
550 File not found

So the :0-10c is interpreted as part of the filename it seems. Fail. Any thoughts?

share|improve this question

3 Answers 3

up vote 5 down vote accepted

Use curl. From the man page:

   -r/--range <range>
          (HTTP/FTP/FILE)  Retrieve  a byte range (i.e a partial document)
          from a HTTP/1.1, FTP server or a local FILE. Ranges can be spec-
          ified in a number of ways.

          0-499     specifies the first 500 bytes

          500-999   specifies the second 500 bytes

          -500      specifies the last 500 bytes

          9500-     specifies the bytes from offset 9500 and forward

          0-0,-1    specifies the first and last byte only(*)(H)

          500-700,600-799
                    specifies 300 bytes from offset 500(H)

However, note that the SIZE extension must be supported by the server for this to work.

share|improve this answer
    
whoa! That is...coincidental... –  Matt Simmons Jun 3 '09 at 15:30
    
Haha, wow, thanks guys, that's exactly what I needed, I wish I could give you both credit for the answer, but sadly, I only get one checkmark so I guess Supermathie gets it for having faster ^V ^C skills :) –  Jax Jun 3 '09 at 15:39

I think you want to use curl for this

From the man page:

   -r/--range <range>
          (HTTP/FTP/FILE)  Retrieve  a byte range (i.e a partial document)
          from a HTTP/1.1, FTP server or a local FILE. Ranges can be spec‐
          ified in a number of ways.

          0-499     specifies the first 500 bytes

          500-999   specifies the second 500 bytes

          -500      specifies the last 500 bytes

          9500-     specifies the bytes from offset 9500 and forward
share|improve this answer
    
I think I beat you to it by like 5 seconds or so :p –  MikeyB Jun 3 '09 at 15:33
    
You missed the caveat: <pre>TP range downloads only support the simple syntax ’start-stop’ (optionally with one of the numbers omitted). It depends on the non-RFC command SIZE.</pre> –  David Pashley Jun 3 '09 at 15:35

Schemes like this depends heavily on the implementation of the server. Some servers support a lot more features than others.

I would investigate some way of splitting the file up or consider a custom application that will send the range you ask for.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.