gnewsg at gmail.com
Mon Apr 30 00:19:32 CEST 2007
On 26 Apr, 16:29, Florian Demmer <fdem... at gmail.com> wrote:
> I have a number of ftp uploads running in parallel using
> ftplib.storbinary and threading and in case one of them fails I need
> to interrupt all the others (but not exit the program completely)...
> do you guys have an idea how i could implement the interruption as
> cleanly as possible?
You could interrupt the transfer by directly using the lower 'ftp-
data' socket instead of the storbinary() method.
Try the following code (not tested):
file = open('file.ext', 'r')
ftp = ftplib.FTP()
conn = ftp.transfercmd('stor file.ext', rest=None)
# the 'shared' var. change it to
# 1 when you want to stop the transfer
stop = 0
chunk = file.read(8192)
if not chunk:
More information about the Python-list