Wrote this script to send a zip file that gets created every day and sent to a FTP server. In line 16, getting a windows 183 error cannot create file that already exists. I am using os.rename, and it works if I run it stand alone. Any ideas?
import ftplib
import os
import sys
import traceback
import datetime
today = datetime.date.today()
host='mail.freshfoodconcepts.com'
port='21'
login='ftpclient'
password='74Dog91'
some_directory='Warwick'
fullname='C:\\crunchtime'
rb='crunsend.zip'
os.rename("c:\\crunchtime\\crunsend.zip", "c:\\kmfc\\crunchtime" + today.strftime("%m%d%y") + ".zip")
print "Files:", 'c:\\crunchtime\\crunsend.zip'
print "Logging in..."
ftp = ftplib.FTP()
ftp.connect(host, port)
print ftp.getwelcome()
try:
try:
ftp.login(login, password)
ftp.cwd(some_directory)
# move to the desired upload directory
print "Currently in:", ftp.pwd()
print "Uploading...",
fullname = 'c:\\crunchtime\\crunsend' + today.strftime("%m%d%y") + '.zip'
name = os.path.split(fullname)[1]
f = open(fullname, "rb")
ftp.storbinary('STOR ' + name, f)
f.close()
print "OK"
print "Files:"
print ftp.retrlines('LIST')
finally:
print "Quitting..."
ftp.quit()
except:
traceback.print_exc()