Skip to content

Instantly share code, notes, and snippets.

@TimSC
Created May 30, 2015 10:57
Show Gist options
  • Select an option

  • Save TimSC/e567cf38e0a8edcb57e6 to your computer and use it in GitHub Desktop.

Select an option

Save TimSC/e567cf38e0a8edcb57e6 to your computer and use it in GitHub Desktop.
Save FTP folder listing to a local file
import os
from ftplib import FTP
if __name__ == "__main__":
ftp = FTP('ftp.debian.org') # connect to host, default port
ftp.login() # user anonymous, passwd anonymous@
ftp.cwd('debian') # change into "debian" directory
outFile = open("out.txt", "wt")
ftp.retrlines('LIST', lambda x: outFile.write(x+os.linesep)) # list directory contents
ftp.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment