ftp files based on start and finish byte

Gordon McMillan gmcm at hypernet.com
Fri Sep 17 22:27:27 EDT 1999


coby writes:

> Here is a little problem...
> 
> I want to transfer a 15MB file from one ftp sever to another
> using the passive mode...but I can't transfer 15MB at once...I
> can only transfer 5MB at a time...so I need a little script or
> ftp client (???) that will allow me to transfer files based on
> start and finish bytes..ie. I want to specify when to start and
> finish transfer...so basically I will get 3
> 
> five mega byte files..which I can merge together with a merge
> utility and end up with the 15MB file...

Slightly modified from something I've used to stuff huge 
datasets on piles of diskettes:
---------------------------------------------
import glob, sys

def cut(fnm):
    f = open(fnm, 'rb')
    i = 0
    while 1:
        data = f.read(5*(2**20))
        if not data:
            break
        open('%s_%02d' % (fnm, i), 'wb').write(data)
        i = i + 1

def paste(fnm):
    f = open(fnm, 'wb')
    parts = glob.glob(fnm+'*')
    parts.sort()
    for part in parts:
        data=open(part, 'rb').read()
        f.write(data)

if '-c' in sys.argv:
   cut(sys.argv[-1])
elif '-p' in sys.argv:
   paste(sys.argv[-1])
else:
   print "Usage %s [-c|-p] <filename>" % sys.argv[0]
-----------------------------------------------------------------

- Gordon




More information about the Python-list mailing list