1

I'm new to python. I want to access baseURL and eventually get a list of files in one of the sub-directories so I can download/unzip this file. The specific file extension can change so I'm hoping to find a match to the file by just the date (yyyymmdd).

baseURL = 'ftp://prism.nacse.org'

Thanks in advance for your guidance!

My code so far is:

variables  = ['ppt', 'tmax', 'tmin']
nvars = len(variables)



baseURL = 'ftp://prism.nacse.org/daily/'


stDateNum = date.toordinal(date(1981,1,1))  # Year, Month, Day
edDateNum = date.toordinal(date(2017,4,22))

dates = list(range(stDateNum,edDateNum+1))
ndates = len(dates)



for v in range(0,nvars):

    for d in range(0,ndates):

        tmpdate = date.fromordinal(dates[d]).strftime('%Y%m%d') #yyyymmdd
        tmpYR = date.fromordinal(dates[d]).strftime('%Y') #yyyy
        totalpath = baseURL + variables[v] + '/' + tmpYR + '/*_' + tmpdate + '_bil.zip'
Vballer
  • 19
  • 1
  • 3
  • 1
    If you have attempted something(which you should have), can you post it, explaining where you are having problems – KeithC Apr 28 '17 at 02:40
  • 1
    As @KeithC said if you post your code it will be useful for others to dig the problem and post a solution. – Mani Apr 28 '17 at 02:55
  • Thanks guys, I guess I don't even know where to start and/or what to look for to accomplish what I mention above.. – Vballer Apr 28 '17 at 23:32
  • Can you use a wildcard to download a specific file? For instance the file I want to download is this: ftp://prism.nacse.org/daily/ppt/1981/PRISM_ppt_stable_4kmD2_19810101_bil.zip ftp://prism.nacse.org/daily/ppt/1981/(wildcard here)19810101_bil.zip – Vballer Apr 28 '17 at 23:33

1 Answers1

2

You could use Python ftplib, https://docs.python.org/3/library/ftplib.html, as a ftp client. I don't think wildcard downloads are support, so you'd have to do something along the lines of...

  1. Login to the FTP server
  2. Navigate to the desired directory
  3. Get a listing of the files, iterate thorough the files and match according to the desired file format
  4. Download desired files
MD6380
  • 1,007
  • 4
  • 13
  • 26