0

I'm trying to create a python script that will log into an FTP server, change to a specific directory and download all files from that dir.

The FTP server has directories created daily and the dir name matches the date. for example:

drwxr-xr-x 2 user tenant 0 Nov 01 00:00 2017-11-01
drwxr-xr-x 2 user tenant 0 Nov 02 00:00 2017-11-02
drwxr-xr-x 2 user tenant 0 Nov 03 00:00 2017-11-03
drwxr-xr-x 2 user tenant 0 Nov 04 00:00 2017-11-04
drwxr-xr-x 2 user tenant 0 Nov 06 00:00 2017-11-06
drwxr-xr-x 2 user tenant 0 Nov 07 00:00 2017-11-07

I am able to get logged into the server but now how can I change into the directory that matches yesterday's date? For example, if today is 2017-11-07 I would need to change into 2017-11-06. I am using python 2.6.6.

I'm using this which I found from another post:

from datetime import date, timedelta  
yesterday = date.today() - timedelta(1)  

This works but how do I use 'yesterday' in my directory path?

Any help is much appreciated.

djabe
  • 25
  • 6
  • Stackoverflow is no code writing service. You just present a task and not what you've tried yourself and where you failed. It is not even clear what your problem is, i.e. constructing a name based on the current date, changing the working directory with ftplib or something else. – Steffen Ullrich Nov 08 '17 at 15:10
  • Python 2.6.6? Bro.... Also your question is a little too broad. – SuperStew Nov 08 '17 at 15:29
  • Your question has nothing to do with ftplib or even with FTP in general. You are basically asking how to generate a string containing a yesterday date in `yyyy-mm-dd` format. – Martin Prikryl Nov 08 '17 at 15:32
  • @MartinPrikryl Yes, I saw that and it works but I'm not sure how to incorporate 'yesterday' into my chdir command, that's really all I am looking for. – djabe Nov 08 '17 at 15:52
  • You have to use the `strftime` as shown in the other question. – Martin Prikryl Nov 08 '17 at 16:57

0 Answers0