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

Peter A. Schott paschott at no.yahoo.spamm.com
Thu Feb 10 17:22:00 EST 2005


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



More information about the Python-list mailing list