ftplib - file.write, file.close() - verify finished writing locally before delete source?

Discussion in 'Python' started by Peter A. Schott, Feb 10, 2005.

  1. If I want to verify that a file has finished writing before deleting the remote
    file, what would be the best method?

    Current code on Python 2.4:

    #filename - remote FTP server File Name
    #NewFile - local file copy of the remote file
    #objFTP - standard ftplib.FTP object

    NewFile = open(os.path.join(InputPath, RemoteFileName), "wb")
    objFTP.retrbinary("RETR " + filename, NewFile.write)
    NewFile.close()

    #Here is my problem - when I call this directly after NewFile.close(), I end up
    #with 0-byte local file and successfully delete the remote file.

    objFTP.delete(filename)


    Any ideas on how to keep the remote file from being deleted if the local file
    isn't finished writing? Any ideas on why I might be retrieving a 0-byte file
    locally when I call like this? If I remove the delete statement, it seems to
    work.

    TIA,

    -Pete Schott
     
    Peter A. Schott, Feb 10, 2005
    #1
    1. Advertisements

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. Peter A. Schott
    Replies:
    0
    Views:
    492
    Peter A. Schott
    Feb 1, 2005
  2. Dani
    Replies:
    3
    Views:
    655
  3. Nico Leiska
    Replies:
    1
    Views:
    177
    Bullschmidt
    Feb 12, 2004
  4. Richard Schneeman
    Replies:
    16
    Views:
    804
    Daniel Bush
    Aug 27, 2008
  5. Emil Kampp
    Replies:
    4
    Views:
    207
    Emil Kampp
    Dec 10, 2009
  6. Iñaki Baz Castillo
    Replies:
    7
    Views:
    1,270
    Iñaki Baz Castillo
    Jan 12, 2010
  7. Robin

    free source guestbook (finished)

    Robin, Apr 22, 2004, in forum: Perl Misc
    Replies:
    19
    Views:
    2,854
    Malcolm Dew-Jones
    May 3, 2004
  8. Iulian Ilea
    Replies:
    1
    Views:
    477
    pcx99
    Dec 21, 2006
Loading...