ftp design question

Discussion in 'Python' started by nemo, Dec 29, 2008.

  1. nemo

    nemo Guest

    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?
     
    nemo, Dec 29, 2008
    #1
    1. Advertising

  2. nemo

    Steve Holden Guest

    nemo wrote:
    > 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
    --
    Steve Holden +1 571 484 6266 +1 800 494 3119
    Holden Web LLC http://www.holdenweb.com/
     
    Steve Holden, Dec 29, 2008
    #2
    1. Advertising

  3. nemo

    nemo Guest

    On Dec 29, 12:31 pm, Steve Holden <> wrote:
    > nemo wrote:
    > > 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
    > --
    > Steve Holden        +1 571 484 6266   +1 800 494 3119
    > Holden Web LLC              http://www.holdenweb.com/


    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.
     
    nemo, Dec 29, 2008
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. someone

    FTP over SSL vs FTP over SSH

    someone, Apr 24, 2004, in forum: Java
    Replies:
    1
    Views:
    4,591
    iksrazal
    Apr 25, 2004
  2. Replies:
    3
    Views:
    5,659
  3. Nico Grubert
    Replies:
    0
    Views:
    647
    Nico Grubert
    Nov 24, 2005
  4. Nico Grubert
    Replies:
    0
    Views:
    449
    Nico Grubert
    Nov 25, 2005
  5. D. Buck
    Replies:
    2
    Views:
    493
    D. Buck
    Jun 29, 2004
Loading...

Share This Page