ftp design question

N

nemo

Hi,all.
I'm on a toy ftp project and I want it to be convinient for the user
to cancel an undergoing downloading while continue others. The
following code explains:
for file in download_files:
self.ftp.retrbinary('RETR '+file, fileHandler)
Thers seems not a solid way to cancel this transfer and I considered
thread or process but I can't handle this correctly.
Thread: I can't kill the thread in another thread, so...
Process: There seems something wrong(raise an EOFError exception) when
I use Process(target = download_fun, args = (dir,)) for each
downloading after connection built.
Some suggestions?
 
S

Steve Holden

nemo said:
Hi,all.
I'm on a toy ftp project and I want it to be convinient for the user
to cancel an undergoing downloading while continue others. The
following code explains:
for file in download_files:
self.ftp.retrbinary('RETR '+file, fileHandler)
Thers seems not a solid way to cancel this transfer and I considered
thread or process but I can't handle this correctly.
Thread: I can't kill the thread in another thread, so...
Process: There seems something wrong(raise an EOFError exception) when
I use Process(target = download_fun, args = (dir,)) for each
downloading after connection built.
Some suggestions?

How about

for file in download_files:
try:
self.ftp.retrbinary('RETR %s' % file, fileHandler)
except KeyboardInterrupt:
print file, "transfer abandoned"

Then you can cancel a single file transfer with Ctrl/C.

regards
Steve
 
N

nemo

How about

for file in download_files:
    try:
        self.ftp.retrbinary('RETR %s' % file, fileHandler)
    except KeyboardInterrupt:
        print file, "transfer abandoned"

Then you can cancel a single file transfer with Ctrl/C.

regards
 Steve

Thanks your advice,
actually, this ftp has a GUI interface, so I'm considering the
downloading part in another process or thread, whick is s a tricky
part for me to design.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top