views:

50

answers:

2

Suppose I want to transfer just a portion of a file over FTP - is it possible using a standard FTP protocol?

In HTTP I could use a Range header in the request to specify the data range of the remote resource. If it's a 1mb file, I could ask for the bytes from 600k to 700k.

Is there anything like that in FTP? I am reading the FTP RFC, don't see anything, but want to make sure I'm not missing anything.

There's a Restart command in FTP - would that work?


Addendum
After getting Brian Bondy's answer below, I wrote a read-only Stream class that wraps FTP. It supports Seek() and Read() operations on a resource that is read via FTP, based on the REST verb.
Find it at http://cheeso.members.winisp.net/srcview.aspx?dir=streams&file=FtpReadStream.cs

It's pretty slow to Seek(), because setting up the data socket takes a long time. Best results come when you wrap that stream in a BufferedStream.

+1  A: 

Yes you can use the REST command.

REST sets the point at which a subsequent file transfer should start. It is used usually for restarting interrupted transfers. The command must come right before a RETR or STOR and so come after a PORT or PASV.

From FTP's RFC 959:

RESTART (REST) The argument field represents the server marker at which file transfer is to be restarted. This command does not cause file transfer but skips over the file to the specified data checkpoint. This command shall be immediately followed by the appropriate FTP service command which shall cause file transfer to resume.

Read more: http://www.faqs.org/rfcs/rfc959.html#ixzz0jZp8azux

Brian R. Bondy
Excellent. That sets the beginning of the range, which is the first half of the answer. Setting the end of the range to transfer is the other half. I don't think anything exists in FTP to do that, so... I suppose the client needs to just *stop transferring*. Maybe send an Abort command. Need to test.
Cheeso
@Cheeso: Yes that is correct you would simply send an ABOR or disconnect the data connection once you have enough data.
Brian R. Bondy
After trying this out, it seems to be working correctly. Thanks.
Cheeso
A: 

You should check out how GridFTP does parallel transfers. That's using the sort of techniques that you want (and might actually be code that it is better to borrow rather than implementing from scratch yourself).

Donal Fellows