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. 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. Peter A. Schott
    Replies:
    0
    Views:
    383
    Peter A. Schott
    Feb 1, 2005
  2. bruce barker
    Replies:
    0
    Views:
    638
    bruce barker
    Dec 9, 2008
  3. Nico Leiska
    Replies:
    1
    Views:
    102
    Bullschmidt
    Feb 12, 2004
  4. Iñaki Baz Castillo
    Replies:
    7
    Views:
    849
    Iñaki Baz Castillo
    Jan 12, 2010
  5. Iulian Ilea
    Replies:
    1
    Views:
    311
    pcx99
    Dec 21, 2006
Loading...

Share This Page