python - Ftp upload file in directory structure per /year/month/day -


i'm using following function upload files , structure per week day ,

what i'm looking adjust here change directory structure per year/month/day

example /incoming/2016/02/08/filename

if dir or sub dir not exits create upload

which method should use switch per week day deep dir structure per year/month/day

def dir_today ():     """ function determine directory today """     week = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday']     day = week[datetime.today().weekday()]     return day  def ftp_upload (ifn):         """" ftp upload function. destination file appended date , timecode received meta data"""         src = "%s/%s" % (src_loc,ifn)         try:                 create_time = get_meta(ifn)         except:                 create_time = datetime.now().strftime("vid_%y-%m-%d_t_%h-%m-%s")         dst_file = os.path.splitext(ifn)[0] + os.path.splitext(ifn)[1]         upload_directory = ftp_base_directory + '/' + dir_today() + '/'          try:                 ftp_connect = ftplib.ftp(ftp_server, ftp_login, ftp_password)                  try:                         ftp_connect.cwd(upload_directory)                 except ftplib.all_errors:                         ftp_connect.mkd(upload_directory)                         ftp_connect.cwd(upload_directory)                  file = open(src, "rb")                 send = ftp_connect.storbinary("stor "+ dst_file, file)                 ftp_connect.close                 file.close()                 os.remove(src)                  logger.info("moved file %s" %(src))                  oflist.remove(ifn)                 hsize.pop(ifn)                 uploaded.insert(0,ifn)                 try:                         uploaded.pop(9)                 except:                         pass         except exception e:                 logger.info("error: %s" %(repr(e)))          return 

you modify dir_today() return subpath:

def dir_today():     today = date.today()     return '{day.year}/{day.month}/{day.day}'.format(day=today) 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -