B
Bakes
I am writing a python script that performs an identical function to
the 'tail' unix utility, except that it connects to its files over
FTP, rather than the local hard disk.
I am currently using this python script to generate an increasing
'logfile' of garbage.
and use this script to actually download it.
Now, my problem is that I get a very strange error. What should be
happening is the script gets the size of the local file before
downloading all of the external file after that offset.
The error I get is:
ftplib.error_temp: 451-Restart offset 24576 is too large for file size
22852.
451 Restart offset reset to 0
which tells me that the local file is larger than the external file,
by about a kilobyte. Certainly, the local file is indeed that size, so
my local script is doing the right things. I do wonder what is going
wrong, can anyone enlighten me?
the 'tail' unix utility, except that it connects to its files over
FTP, rather than the local hard disk.
I am currently using this python script to generate an increasing
'logfile' of garbage.
import time
for i in range(1, 20000):
time.sleep(0.2)
print i
f = open("data1.log","a")
f.write('%s: This logfile is being automatically generated to help Bakes test his python ftptail. \n' % i)
f.close()
and use this script to actually download it.
import time
import os.path
from ftplib import FTP
#Empty the file
filename = 'data1.log'
file = open(filename, 'w')
file.write('')
file.close()
def handleDownload(block):
file.write(block)
print ".",
# Create an instance of the FTP object
# Optionally, you could specify username and password:
ftp=FTP(host, user, pass)
directory = '/temp'
ftp.cwd(directory)
file = open(filename, 'a')
for i in range(1,20000):
size=os.path.getsize('data1.log')
ftp.retrbinary('RETR ' + filename, handleDownload, rest=size)
file.close()
print ftp.close()
Now, my problem is that I get a very strange error. What should be
happening is the script gets the size of the local file before
downloading all of the external file after that offset.
The error I get is:
ftplib.error_temp: 451-Restart offset 24576 is too large for file size
22852.
451 Restart offset reset to 0
which tells me that the local file is larger than the external file,
by about a kilobyte. Certainly, the local file is indeed that size, so
my local script is doing the right things. I do wonder what is going
wrong, can anyone enlighten me?