-----Original Message----- From: python-list-bounces+shahmed=sfwmd....@python.org [mailto:python-list-bounces+shahmed=sfwmd....@python.org] On Behalf Of Dan M Sent: Thursday, January 06, 2011 11:06 AM To: python-list@python.org Subject: Re: list from FTP server to a text file
On Thu, 06 Jan 2011 10:51:42 -0500, Ahmed, Shakir wrote: > Hi, > > I am trying to create a list in a txt file from an ftp server. The > following code is retrieving the list of the files but could not able to > write in a text file. Any help is highly appreciated. > > Thanks > > > > **************************** > import os > import time > from ftplib import FTP > ftp = FTP("*.org","","") # connect to host, default port ftp.login() > ftp.cwd("/pub/remotefolder/") > ftp.retrlines('NLST') > ****************************** WARNING: I am a newbie! Expect more pythonic ways to do this in other replies from ftplib import FTP ftp = FTP("host", "user", "pass") ftp.cwd("/pub/myfolder") files = ftp.nlst(".") f = open('files.txt', 'w') for file in files: f.write('%s\n' % (file,)) f.close() -- It worked Thanks, shk -- http://mail.python.org/mailman/listinfo/python-list