Use Python to Save an FTP Directory List to File

Written for Python 2.6

#!/usr/bin/python

import ftplib

ftp = ftplib.FTP("ftp.server.com")
ftp.login("username", "password")
ftp.cwd("path/path")

data = []

ftp.dir(data.append)

ftp.quit()

outputFile = open('dirList.txt','wb')

for line in data:
    outputFile.write(line + "\n")

outputFile.close()
Reblog this post [with Zemanta]

Leave a Reply