0

I am trying to download all the master.idx files of different quarters in different years. The EDGAR FTP is structured like this: "edgar/full-index/2011/QTR3/", and in the QTR3 folder is the master.idx file.

I tried to access the folder of different years by doing a loop, but it returns me 550 Error. So I tried to test the loop like this.

from ftplib import FTP
ftp = FTP('ftp.sec.gov')
ftp.set_debuglevel(2)
ftp.login('anonymous','shijiehkj@gmail.com')

QtrList = ('QTR1','QTR2','QTR3','QTR4')
year = 2013    
ftp.cwd('edgar/full-index/'+str(year))
print(ftp.nlst())
year = 2014    
ftp.cwd('edgar/full-index/'+str(year))
print(ftp.nlst())
ftp.quit()

The year = 2013 part works, but when I reset the year = 2014, it gives me the error like this.

550 edgar/full-index/2014: No such file or directory

However if I add the log-in info again between the 2013 and 2014, like this

year = 2013    
ftp.cwd('edgar/full-index/'+str(year))
print (ftp.nlst("QTR1"),year)

ftp = FTP('ftp.sec.gov')
ftp.set_debuglevel(2)
ftp.login('anonymous','shijiehkj@gmail.com')

year = 2014    
ftp.cwd('edgar/full-index/'+str(year))
print (ftp.nlst("QTR1"),year)

There is no error. Anybody knows why and could give a quick solution to access the master.idx in each Quarter folder in each year folder?

1 Answers1

0

Shijie,

Your error is due to relative vs. absolute pathing on the FTP server. Throw a '/' in front of your paths and you should be good to go. I believe it's trying to do a cd {your new FTP directory} from within the sub-directory. Kind of like being able to cd /home from any location, but not being able to cd home from any location.

from ftplib import FTP
ftp = FTP('ftp.sec.gov')
ftp.set_debuglevel(2)
ftp.login('anonymous','shijiehkj@gmail.com')

QtrList = ('QTR1','QTR2','QTR3','QTR4')
year = 2013    
ftp.cwd('/edgar/full-index/'+str(year))
print(ftp.nlst())
year = 2014    
ftp.cwd('/edgar/full-index/'+str(year))
print(ftp.nlst())
ftp.quit()
R Scott
  • 176
  • 2
  • 5