Using Python, how can I wait for a file to be uploaded (using ftp) before deleting it?
uploadFile(ftp, filepath,namef)
# ............Here, I need to wait........
os.remove(filepath)
Any ideas?
Using Python, how can I wait for a file to be uploaded (using ftp) before deleting it?
uploadFile(ftp, filepath,namef)
# ............Here, I need to wait........
os.remove(filepath)
Any ideas?
You could make a MD5 checksum, upload it, then download it, compare the MD5, and then delete if you have a match.
Bonus: if your server supports MD5 as a site extension, you don't have to download, you can just ask the server for the MD5.
Using the ftplib as linked by Randolpho, it looks like you want to use:
FTP.storbinary(command, file[, blocksize, callback])
Before you transfer the file, calculate how many blocks (of size blocksize it will take to transfer the file. Your callback function can count the number of times it is called and when the counter reaches the number of blocks, you know that the entire file has been transferred. Your callback function can then call the function that deletes the file.