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

P

Peter A. Schott

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
 

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,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top