关于下载续传(resume),已经有很多软件都支持了。最简单的是在ftp这个客户端程序中reget命令就行;比较著名的是wget,同时支持ftp 和http以及proxy,Redhat发行版中已经包含了它。一个比较简单的程序是snarf,写得很简明,可供一般的程序员参考。另外有个人用 perl写了个http续传的脚本Get Right,收录在这儿供perl程序员参考.不知是否有人在写类似NetAnts的分段下载的软件?
----------------------
#!/usr/bin/perl
use IO::Socket;
if ($#ARGV <= 0) {
print STDERR "usage: getright nn";
print STDERR " : eg. http://www.server.dom:port/path/file.extn";
print STDERR ": eg. filename.extn";
exit(0);
} else {
open(FILE, "+>>".$ARGV[1]) or die "Cannot open $ARGV[1] for append: $!";
($length = sysseek(FILE,0,2)) =~ s!.*([0-9]+).*!$1!g;
print STDERR "Attempting to resume $ARGV[1] from byte: $lengthn";
}
if ($ARGV[0] =~ m!^ (?:http://)? (.*?) (?::([0-9]+))? (/.*)$!x)
{ ($server,$port,$path) = ($1, $2 || 80, $3); }
print "[$server] [$port] [$path]n";
$socket = IO::Socket::INET->new(PeerAddr => $server,
PeerPort => $port,
Proto => "tcp",
Type => SOCK_STREAM) or die "Cannot connect: $!";
print $socket "GET $path HTTP/1.0n";
print $socket "Host: $servern";
print $socket "Range: bytes=$length-n";
print $socket "Connection: closenn";
if (!(($reply = <$socket>) =~ /HTTP/1.[01] 206 Partial Content/)) {
$reply =~ s!(.*)rn!$1!;
print STDERR "Failed [$reply]n";
print STDERR "Invalid URL/Unrecognized Reply/Resume Not Supported.n";
close($socket); exit(0);
} else {
print STDERR "Received valid HTTP reply.n";
}
while (($mime = <$socket>) =~ /w+: /) {
if ($mime =~ /Content-Range:sbytess([0-9]+)-([0-9]+)/([0-9]+)/)
{ ($start,$finish,$filesize) = ($1, $2, $3); }
if ($mime =~ /Content-Length:s([0-9]+)/) { $total = $1; }
}
print STDERR "Receiving data: ";
while ($data = <$socket>) {
$recieved += length($data);
$percentage= int((($start+$recieved) / $filesize) * 100);
print STDERR $percentage."%"."b"x(length($percentage)+1);
print FILE $data;
}
print STDERR "100%n";
close(FILE);
close($socket);