from ftplib import FTP import os import gzip from pprint import pprint ftp = FTP("ftp.wwpdb.org") ftp.login() ftp.cwd("/pub/pdb/data/structures/divided/XML/") i = 0 for name in ftp.nlst(): i += 1 if i > 3: continue if name is None: ftp.cwd('../') continue print("Listing the " + name + " directory.") try: ftp.cwd(name) except: # ftplib.error_perm(): continue values = ftp.mlsd() if values is None: ftp.cwd('../') continue #pprint(values) #continue # [x * x for x in range(10) if x % 2 != 0] print("got here") for file in [value for value in values if value is not None]: pprint(file) # unzip = gzip.decompress(file) # pprint("Unzipped" + unzip) # pprint(unzip) # print("File name: " + unzip) ftp.cwd('../') ftp.quit()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question