1

I put together some code that loops through all folders in an FTP portal, and lists all the files, and zipped files,in the folder. This works great!

import csv
import ftplib
ftp = ftplib.FTP('portal', 'user_name', 'pswd')  
contents1 = ftp.retrlines('LIST')
print(contents1)

ftp.nlst()
contents2 = ftp.nlst('emm')
print(contents2)


outF = open('C:\\path_to_file\\test.txt', 'w')
for line in contents1:
  # write line to output file
  outF.write(line)
  outF.write("\n")
  for line in contents2:
      # write line to output file
      outF.write(line)
      outF.write("\n")
outF.close()

I don't want to download all files, because there are so, so, so many, and as such, this kind of task will take a very long time. I just want a snapshot, or inventory, of the contents of all folders, and sub folders, with details of all files (at least size of each file, maybe date of each file, and maybe a few other basic analytics too). How can I do that? TIA.

ASH
  • 20,759
  • 19
  • 87
  • 200
  • Hello there. I'm trying to get the file size, date files was created, and a few other basic properties of all files in all folders. Or, at least get the properties of the zipped folders (size, date created, etc.). How can I do that? – ASH Dec 03 '18 at 20:25
  • So use the code from my answer to the linked question. Just instead of `namelist()`, call [`infolist()`](https://docs.python.org/3/library/zipfile.html#zipfile.ZipFile.infolist). – Martin Prikryl Dec 03 '18 at 20:41
  • Thanks. This looks like it will be very useful, but I can't get it to run. I'm getting a message that reads: NameError: name 'path' is not defined. I'm using the second method: zipstring = StringIO() What am I doing wrong here? – ASH Dec 03 '18 at 21:15
  • OK, I made a really dumb mistake before. I just changed the 'ftp' to the actual folder name I'm hitting. Now, I'm getting the following error: NameError: name 'StringIO' is not defined. How can I resolve this issue? – ASH Dec 03 '18 at 21:37
  • Oh, wait, I added in several libraries: import io from io import StringIO import string import pandas as pd from pandas.compat import StringIO ...and... from collections import Counter Now, it appears to be working. It seems to be running very, very, very slow. Is that normal? – ASH Dec 03 '18 at 21:45
  • This is running very, very slow. Where do the final results get output? Thanks again. – ASH Dec 03 '18 at 22:01
  • *It seems to be running very, very, very slow:* That's way too vague. We do not really know what you are doing. How many archives are you listing. Whether you used the code correctly, etc. If my answer to the duplicate question helped you move on, please consider upvoting it. And if you have problems with the code, ask a new separate and more specific question. + *Where do the final results get output?*: I have no idea what you mean. Again, consider asking separate question with code and desired results. – Martin Prikryl Dec 04 '18 at 06:49

0 Answers0